{"text": "module etox_module\n implicit none\n\n contains\n real function etox(x)\n implicit none\n\n real, intent(in) :: x\n real :: term\n integer :: n\n real, parameter :: tol = 1.e-6\n\n etox = 1.\n term = 1.\n n = 0\n do\n n = n+1\n term = term*(x/n)\n etox = etox+term\n if (abs(term)<=tol) exit\n end do\n end function\nend module\n\nprogram ch1306\n ! The Evaluation of e**x\n use etox_module\n implicit none\n\n real, parameter :: x = 1.\n real :: y\n\n print *, 'Fortran intrinsic ', exp(x)\n y = etox(x)\n print *, 'User defined etox ', y\nend program\n", "meta": {"hexsha": "8faba360a3b86140356789570aedde6f0fe3406c", "size": 668, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch13/ch1306.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": "ch13/ch1306.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": "ch13/ch1306.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": 18.0540540541, "max_line_length": 41, "alphanum_fraction": 0.497005988, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.900529778109184, "lm_q1q2_score": 0.8495125763800676}} {"text": "module euler \n implicit none \n private\n public :: binomial\n public :: digit\n public :: digit16\n public :: gcd\n public :: is_factor\n public :: is_palindrome\n public :: is_palindrome16\n public :: is_prime\n public :: number_length\n public :: sum_of_divisors\n public :: tau\n public :: is_triangular\n public :: is_square\n public :: is_pentagonal\n public :: is_hexagonal\n public :: is_heptagonal\n public :: is_octagonal\n\ncontains \n\n ! Binomial coefficient\n pure function binomial(n,k)\n implicit none\n integer*8, intent(in) :: n,k\n integer*16 :: temp\n integer*8 :: i,binomial\n\n temp=1\n do i=n-k+1,n\n temp=temp*i\n end do\n do i=1,n-k\n temp=temp/i\n end do\n binomial=temp\n end function binomial\n \n ! Get the dth digit from the decimal representation of n.\n pure function digit(n,d)\n implicit none\n integer, intent(in) :: n, d\n integer :: digit\n digit = mod(n,10**d)/(10**(d-1))\n end function digit\n\n ! Get the dth digit from the decimal representation of n.\n pure function digit16(n,d)\n implicit none\n integer*16, intent(in) :: n\n integer, intent(in) :: d\n integer :: digit16\n digit16 = mod(n,10_16**d)/(10_16**(d-1))\n end function digit16\n\n ! gcd\n pure function gcd(a0,b0)\n implicit none\n integer*8, intent(in) :: a0, b0\n integer :: a, b, t, gcd\n\n a=a0\n b=b0\n do while (b /= 0)\n t=b\n b=mod(a,b)\n a=t\n end do\n gcd=a\n end function gcd\n\n ! Returns .true. if f is a factor of n, otherwise returns .false.\n pure function is_factor(f,n)\n implicit none\n integer*8, intent(in) :: n\n integer, intent(in) :: f\n logical :: is_factor\n is_factor = (mod(n,f)==0)\n end function is_factor\n\n ! Returns .true. if the decimal representation of n is a palindrome,\n ! otherwise returns .false.\n pure function is_palindrome(n)\n implicit none\n integer, intent(in) :: n\n integer :: i, j, digits\n logical :: is_palindrome\n\n digits = ceiling(log10(dble(n)))\n is_palindrome = .true.\n\n do i=1,digits\n j = digits+1-i\n if (digit(n,i) /= digit(n,j)) then\n is_palindrome = .false.\n exit\n end if\n end do\n end function is_palindrome\n\n ! Returns .true. if the decimal representation of n is a palindrome,\n ! otherwise returns .false.\n pure function is_palindrome16(n)\n implicit none\n integer*16, intent(in) :: n\n real*16 :: temp\n integer :: i, j, digits\n logical :: is_palindrome16\n\n temp=n*1.0\n digits = ceiling(log10(temp))\n is_palindrome16 = .true.\n\n do i=1,digits\n j = digits+1-i\n if (digit16(n,i) /= digit16(n,j)) then\n is_palindrome16 = .false.\n exit\n end if\n end do\n end function is_palindrome16\n\n ! Returns .true. if n is a prime number, otherwise return .false.\n pure function is_prime(n)\n implicit none\n integer*8, intent(in) :: n\n integer :: i\n logical :: is_prime\n\n if (n == 1) then\n is_prime = .false.\n else\n is_prime = .true.\n do i=2,min(n-1,ceiling(sqrt(dble(n))))\n if (mod(n,i) == 0) then\n is_prime = .false.\n exit\n end if\n end do\n end if\n end function is_prime\n\n ! Get the length of the decimal representation of a number\n pure function number_length(n)\n implicit none\n integer*8, intent(in) :: n\n integer :: number_length\n real*8 :: temp\n\n temp=log10(dble(n))\n if (mod(temp,1.0_8)==0.0_8) temp=temp+0.01\n number_length = ceiling(temp)\n end function number_length\n\n ! Returns the sum of proper divisors\n pure function sum_of_divisors(n)\n implicit none\n integer*8, intent(in) :: n\n integer*8 :: i\n integer*8 :: sum_of_divisors\n\n sum_of_divisors=1\n do i=2,n-1\n if (mod(n,i) == 0) then\n sum_of_divisors=sum_of_divisors+i\n end if\n end do\n end function sum_of_divisors\n\n ! Euler tau function: The number of divisors of n\n pure function tau(n)\n implicit none\n integer*8, intent(in) :: n\n integer*8 :: current_n,p\n integer :: a,tau\n\n tau=1\n current_n=n\n\n1 if (is_prime(current_n)) then ! shortcut for prime numbers\n tau=tau*2\n current_n=1\n end if\n do p=2,current_n\n if (is_prime(p) .and. (mod(current_n,p) == 0)) then\n do a=ceiling(log(dble(n))/log(dble(p))),1,-1\n if (mod(current_n,p**a) == 0) then\n exit\n end if\n end do\n tau=tau*(a+1)\n current_n=current_n/(p**a)\n go to 1\n end if\n end do\n end function tau\n\n pure function is_triangular(m)\n implicit none\n integer, intent(in) :: m\n double precision :: temp\n logical :: is_triangular,plus,minus\n\n temp=(1 + sqrt(1.0 + 4*2*m))/2\n plus=(temp>0) .and. (mod(temp,1.0)==0.0)\n temp=(1 - sqrt(1.0 + 4*2*m))/2\n minus=(temp>0) .and. (mod(temp,1.0)==0.0)\n is_triangular=plus .or. minus\n\n end function is_triangular\n\n pure function is_square(m)\n implicit none\n integer, intent(in) :: m\n logical :: is_square\n\n is_square=mod(sqrt(dble(m)),1.0)==0.0\n\n end function is_square\n\n pure function is_pentagonal(m)\n implicit none\n integer, intent(in) :: m\n double precision :: temp\n logical :: is_pentagonal,plus,minus\n\n temp=(1 + sqrt(1.0 + 4*3*2*m))/6\n plus=(temp>0) .and. (mod(temp,1.0)==0.0)\n temp=(1 - sqrt(1.0 + 4*3*2*m))/6\n minus=(temp>0) .and. (mod(temp,1.0)==0.0)\n is_pentagonal=plus .or. minus\n\n end function is_pentagonal\n\n pure function is_hexagonal(m)\n implicit none\n integer, intent(in) :: m\n double precision :: temp\n logical :: is_hexagonal,plus,minus\n\n temp=(1 + sqrt(1.0 + 4*2*m))/4\n plus=(temp>0) .and. (mod(temp,1.0)==0.0)\n temp=(1 - sqrt(1.0 + 4*2*m))/4\n minus=(temp>0) .and. (mod(temp,1.0)==0.0)\n is_hexagonal=plus .or. minus\n\n end function is_hexagonal\n\n pure function is_heptagonal(m)\n implicit none\n integer, intent(in) :: m\n double precision :: temp\n logical :: is_heptagonal,plus,minus\n\n temp=(3 + sqrt(9.0 + 4*5*2*m))/10\n plus=(temp>0) .and. (mod(temp,1.0)==0.0)\n temp=(3 - sqrt(9.0 + 4*5*2*m))/10\n minus=(temp>0) .and. (mod(temp,1.0)==0.0)\n is_heptagonal=plus .or. minus\n\n end function is_heptagonal\n\n pure function is_octagonal(m)\n implicit none\n integer, intent(in) :: m\n double precision :: temp\n logical :: is_octagonal,plus,minus\n\n temp=(2 + sqrt(4.0 + 4*3*m))/6\n plus=(temp>0) .and. (mod(temp,1.0)==0.0)\n temp=(2 - sqrt(4.0 + 4*3*m))/6\n minus=(temp>0) .and. (mod(temp,1.0)==0.0)\n is_octagonal=plus .or. minus\n\n end function is_octagonal\n\nend module euler\n", "meta": {"hexsha": "f818bac4fbda2b044f9aa9e57006aba3f2425c2c", "size": 6990, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "euler.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": "euler.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": "euler.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": 24.9642857143, "max_line_length": 70, "alphanum_fraction": 0.5732474964, "num_tokens": 2155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.969785409439575, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8493254352729345}} {"text": "PROGRAM LargestFactorialInteger\r\n!---\r\n! This Program determines the largest n for which n! can be stored in a 32 bit integer\r\n!---\r\nIMPLICIT NONE\r\n\r\nINTEGER :: v, n\r\nREAL :: r, rprev\r\n\r\n!- First, the largest possbile signed 32bit integer value is 2**31-1\r\nv = 2**31-1\r\nPRINT *, \"The largest integer is:\"\r\nPRINT *, v\r\n!- Next, we'll start with n = 1, n! == 1\r\nn = 1\r\nr = 1\r\n!- continue computing n! with incresing n, until we surpass v\r\nDO WHILE (v .gt. r)\r\n n = n + 1\r\n \trprev = r\r\n r = r * n\r\nEND DO\r\n!- Now notice n will increase even if r becomes greater than v, so n--\r\nn = n -1\r\nv = rprev\r\nPRINT *, \"The largest possible values of n and n! within the 32bit integer is:\"\r\nPRINT *, \"n:\", n\r\nPRINT *, \"n!:\", v\r\n\r\nEND PROGRAM LargestFactorialInteger", "meta": {"hexsha": "7bbcc0170f2b4acdad85101b6cc98923732bfee2", "size": 759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Additional Work/Q1_LargestFactorialInteger.f90", "max_stars_repo_name": "Chris-Drury/COMP3731", "max_stars_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Additional Work/Q1_LargestFactorialInteger.f90", "max_issues_repo_name": "Chris-Drury/COMP3731", "max_issues_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Additional Work/Q1_LargestFactorialInteger.f90", "max_forks_repo_name": "Chris-Drury/COMP3731", "max_forks_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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.3, "max_line_length": 87, "alphanum_fraction": 0.6337285903, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9790357585701875, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.8488590111235345}} {"text": "program meanVarianceSD\r\n \r\n implicit none;\r\n integer ,parameter:: MAX_SIZE = 50;\r\n integer n;\r\n integer i;\r\n real sum, mean, variance, sd;\r\n real ,dimension(MAX_SIZE)::arr\r\n \r\n print *, 'Enter no of terms'\r\n read *, n\r\n \r\n !read input\r\n i = 1 \r\n do while(i <= n)\r\n read *, arr(i);\r\n i = i + 1\r\n end do\r\n !or read/write directly\r\n !read (*,*),(arr(i),i = 1, n)\r\n !write (*,*),(arr(i),i = 1, n)\r\n \r\n \r\n ! print elements \r\n ! print *, 'Array elements are as :'\r\n ! do i = 1 , n, 1\r\n ! print *, arr(i) , \" *\"\r\n ! end do\r\n \r\n \r\n sum = 0; \r\n do i = 1, n, 1\r\n sum = sum + arr(i);\r\n end do\r\n \r\n mean = sum / n;\r\n \r\n variance = 0\r\n do i = 1, n, 1\r\n variance = variance + (arr(i) - mean)**2; ! ** === ^\r\n end do\r\n variance = variance / (n - 1)\r\n sd = SQRT(variance)\r\n\r\n print *, \"Mean : \" ,mean\r\n print *, \"Variance : \" ,variance\r\n print *, \"SD : \" ,sd\r\n \r\n end program meanVarianceSD", "meta": {"hexsha": "e27359f77ec9ddc1dce85bddafd0bcef834923e0", "size": 980, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/MeanVariance.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/MeanVariance.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/MeanVariance.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": 20.0, "max_line_length": 59, "alphanum_fraction": 0.4642857143, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561730622296, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.8485116331457124}} {"text": "\t!>@author\r\n\t!>Paul Connolly, The University of Manchester\r\n\t!>@brief\r\n\t!>code to do a linear interpolation based on neville's algorithm\r\n\t!> https://en.wikipedia.org/wiki/Neville%27s_algorithm\r\n\t!>param[in] xarr,yarr,x: arrays and position\r\n\t!>param[inout] y,dy: value of y and error in y\r\n\tsubroutine poly_int(xarr,yarr,x,y,dy)\r\n\t use numerics_type\r\n use numerics, only : assert_eq,iminloc,numerics_error\r\n implicit none\r\n real(wp), dimension(:), intent(in) :: xarr,yarr\r\n real(wp), intent(in) :: x\r\n real(wp), intent(out) :: y,dy\r\n integer(i4b) :: m,n,ns\r\n real(wp), dimension(size(xarr)) :: c,d,factor,dx\r\n n=assert_eq(size(xarr),size(yarr),'poly_int')\r\n c=yarr\r\n d=yarr\r\n dx=xarr-x\r\n ns=iminloc(abs(dx))\r\n y=yarr(ns) ! nearest neighbour\r\n ns=ns-1\r\n do m=1,n-1 ! there are n-1 additional terms\r\n factor(1:n-m)=dx(1:n-m)-dx(1+m:n)\r\n if (any(factor(1:n-m) == 0.0)) &\r\n call numerics_error('poly_int: calculation failure')\r\n factor(1:n-m)=(c(2:n-m+1)-d(1:n-m))/factor(1:n-m) ! 3.1.3 recurrence relation\r\n d(1:n-m)=dx(1+m:n)*factor(1:n-m) ! 3.1.5 formulae\r\n c(1:n-m)=dx(1:n-m)*factor(1:n-m)\r\n if (n-m > 2*ns) then\r\n dy=c(ns+1)\r\n else\r\n dy=d(ns)\r\n ns=ns-1\r\n end if\r\n y=y+dy\r\n end do\r\n\tend subroutine poly_int\r\n", "meta": {"hexsha": "39fb147924b3dd559dc009c2fa67b63043362208", "size": 1483, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "poly_int.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": "poly_int.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": "poly_int.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": 37.075, "max_line_length": 90, "alphanum_fraction": 0.5300067431, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305360354471, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.8484106355310929}} {"text": "!\n! newton1d.f95\n! \n! Josh Kaplan\n!\n! This is a generic implementation of Newton's Method in 1-dimension. \n! Edit the function, f, and it's derivative, df, for your specific problem.\n!\n! Compile: run \"gfortran newton1d.f95 -o newton\"\n! Execute: run \"./newton\"\n!\n\nprogram NewtonsMethod\n\ninteger :: N \nreal :: tol, x, f, df \n\nx = 10 ! Initial guess <= EDIT THIS LINE\nN = 100 ! Maximum Iterations <= EDIT THIS LINE\ntol = 1e-3 ! Tolerance <= EDIT THIS LINE\n\n! Netwon's Method \ndo i = 1, N\n f = 2*x**2 - 32 ! Function f(x) <= EDIT THIS LINE \n df = 4*x ! Derivative f'(x) <= EDIT THIS LINE\n x = x - f/df ! Improved guess\n\n ! If close enough, exit loop\n if (ABS(f) < tol) then \n exit \n end if\nend do\nprint '(\"Converged to\",f6.3,\" in\",i2,\" iterations\")', x, i\n\nend program NewtonsMethod", "meta": {"hexsha": "a66d6ec072122b08cc0b7acaf28e34b16a731771", "size": 968, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "newtons_method/fortran/newton1d.f95", "max_stars_repo_name": "josh-kaplan/numerical-methods", "max_stars_repo_head_hexsha": "5e596899352507fed7f2b831c6e369e2b856783f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newtons_method/fortran/newton1d.f95", "max_issues_repo_name": "josh-kaplan/numerical-methods", "max_issues_repo_head_hexsha": "5e596899352507fed7f2b831c6e369e2b856783f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newtons_method/fortran/newton1d.f95", "max_forks_repo_name": "josh-kaplan/numerical-methods", "max_forks_repo_head_hexsha": "5e596899352507fed7f2b831c6e369e2b856783f", "max_forks_repo_licenses": ["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.6571428571, "max_line_length": 75, "alphanum_fraction": 0.5247933884, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551576415562, "lm_q2_score": 0.8791467564270271, "lm_q1q2_score": 0.848249282262462}} {"text": "function Interpolate(opt,N,dx,F,x)\n\nimplicit none\n\nreal (kind=8) :: Interpolate,dx,x\nreal (kind=8) :: aux1,aux2\nreal (kind=8) :: Fbefore,Fafter,Fcurr\ninteger (kind=4) :: opt\ninteger (kind=4) :: N,ix\n\nreal (kind=8),dimension (0:N+1) :: F\n\nix = int(x/dx)+1\naux1 = x-(ix-1)*dx\naux2 = dx-aux1 \n\nif (opt==0) then\n \n Interpolate = (aux1*F(ix)+aux2*F(ix-1))/dx\n\nelse if (opt==1) then\n\n Fbefore = (aux1*F(ix-1)+aux2*F(ix-2))/dx\n Fafter = (aux1*F(ix+1)+aux2*F(ix))/dx\n\n Interpolate = 0.5d0*(Fafter-Fbefore)/dx\n\nelse if (opt==2) then\n\n Fbefore = (aux1*F(ix-1)+aux2*F(ix-2))/dx\n Fcurr = (aux1*F(ix)+aux2*F(ix-1))/dx\n Fafter = (aux1*F(ix+1)+aux2*F(ix))/dx\n\n Interpolate = (Fafter-2.d0*Fcurr+Fbefore)/(dx*dx)\n\nelse \n \n print *, 'Parameter opt in function interpolate crash!!!!!'\n\nend if\n\nreturn\nend function Interpolate\n", "meta": {"hexsha": "5a83fd921c8a8fb322792e207f94f6b977ed71a1", "size": 844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Algorithm/DiffusionMonteCarlo/interpolate.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/DiffusionMonteCarlo/interpolate.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/DiffusionMonteCarlo/interpolate.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": 19.1818181818, "max_line_length": 62, "alphanum_fraction": 0.6125592417, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.8480712355463074}} {"text": "FUNCTION in_circle(pos_x, pos_y, r)\n IMPLICIT NONE\n REAL(16), INTENT(IN) :: pos_x, pos_y, r\n LOGICAL :: in_circle\n\n in_circle = (pos_x ** 2 + pos_y ** 2) < r ** 2\n\nEND FUNCTION in_circle \n\nPROGRAM monte_carlo\n \n IMPLICIT NONE\n \n INTERFACE\n FUNCTION in_circle(pos_x, pos_y, r) \n IMPLICIT NONE\n REAL(16), INTENT(IN) :: pos_x, pos_y, r\n LOGICAL :: in_circle\n END FUNCTION in_circle \n END INTERFACE\n \n INTEGER :: i,n\n REAL(16) :: pos_x,pos_y, r, pi_est, pi_count, pi_error, pi\n \n ! Calculate Pi from trigonometric functions as reference\n pi = DACOS(-1.d0)\n n = 1000000\n r = 1d0\n pos_x = 0d0\n pos_y = 0d0\n pi_count = 0d0\n \n DO i=0,n\n \n CALL RANDOM_NUMBER(pos_x)\n CALL RANDOM_NUMBER(pos_y)\n \n IF (in_circle(pos_x, pos_y, r) .EQV. .TRUE.) THEN \n \n pi_count = pi_count + 1d0\n \n END IF\n END DO\n \n pi_est = 4d0 * pi_count / n\n pi_error = 100d0 * (abs(pi_est - pi)/pi)\n \n WRITE(*,'(A, F12.4)') 'The pi estimate is: ', pi_est\n WRITE(*,'(A, F12.4, A)') 'Percent error is: ', pi_error, ' %'\n \nEND PROGRAM monte_carlo\n", "meta": {"hexsha": "6dd729378dacae0be5c14f5b678ae2f47dd03b45", "size": 1246, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "contents/monte_carlo_integration/code/fortran/monte_carlo.f90", "max_stars_repo_name": "atocil/algorithm-archive", "max_stars_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "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/monte_carlo_integration/code/fortran/monte_carlo.f90", "max_issues_repo_name": "atocil/algorithm-archive", "max_issues_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "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/monte_carlo_integration/code/fortran/monte_carlo.f90", "max_forks_repo_name": "atocil/algorithm-archive", "max_forks_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "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": 23.9615384615, "max_line_length": 65, "alphanum_fraction": 0.5321027287, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900508, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8479300731816801}} {"text": "SUBROUTINE CANS( T, omega, Pulse, SF, NSD, IT, PulseTitle )\r\n\r\n ! Computes the source time series\r\n\r\n ! T is the time\r\n ! omega is some frequency characterizing the pulse\r\n ! Pulse is the letter indicating which pulse\r\n ! S is the time series\r\n\r\n IMPLICIT NONE\r\n REAL, PARAMETER :: pi = 3.141592\r\n\r\n INTEGER, INTENT( IN ) :: NSD, IT\r\n REAL, INTENT( IN ) :: T, omega\r\n CHARACTER, INTENT( IN ) :: Pulse*1\r\n COMPLEX, INTENT( OUT ) :: SF( NSD, * )\r\n CHARACTER, INTENT( OUT ) :: PulseTitle*( * )\r\n INTEGER :: NSIG\r\n REAL :: S, F, A, T0, TS, TC, U\r\n\r\n S = 0.0\r\n F = omega / ( 2.0 * pi )\r\n\r\n IF ( T > 0.0 ) THEN ! Evaluate selected Pulse\r\n SELECT CASE ( Pulse )\r\n CASE ( 'P' ) ! Pseudo gaussian\r\n ! (peak at 0, support [0, 3F]\r\n IF ( T <= 1.0 / F ) S = 0.75 - COS( omega * T ) + 0.25*COS( 2.0 * omega * T )\r\n PulseTitle = 'Pseudo gaussian'\r\n\r\n CASE ( 'R' ) ! Ricker wavelet\r\n ! (peak at F, support [0, 2F]\r\n U = omega * T - 5.0\r\n S = 0.5 * ( 0.25*U*U - 0.5 ) * SQRT( pi ) * EXP( -0.25*U*U )\r\n PulseTitle = 'Ricker wavelet'\r\n\r\n CASE ( 'A' ) ! Approximate Ricker wavelet\r\n ! (peak at F, support [0, 2.5F]\r\n TC = 1.55 / F\r\n IF ( T <= TC ) &\r\n & S = 0.48829 * COS( 2.0 * pi * T / TC ) &\r\n & -0.14128 * 4* COS( 4.0 * pi * T / TC ) &\r\n & +0.01168 * 9* COS( 6.0 * pi * T / TC )\r\n PulseTitle = 'Approximate Ricker wavelet'\r\n\r\n CASE ( 'S' ) ! Single sine\r\n ! (peak at F, support [0, infinity], nulls at nF\r\n IF ( T <= 1.0 / F ) S = SIN( omega * T )\r\n PulseTitle = 'Single sine'\r\n\r\n CASE ( 'H' ) ! Hanning weighted four sine\r\n ! (peak at F, support [0, infinity], first null at about 1.5F\r\n IF ( T <= 4.0 / F ) S = 0.5 * SIN( omega * T ) * ( 1 - COS( omega * T / 4.0 ) )\r\n PulseTitle = 'Hanning weighted four sine'\r\n\r\n CASE ( 'N' ) ! N-wave\r\n ! (peak at 1 F, support [0, 4F], [0,3F] OK\r\n IF ( T <= 1.0 / F ) S = SIN( omega * T ) - 0.5 * SIN( 2.0 * omega * T )\r\n PulseTitle = 'N-wave'\r\n\r\n CASE ( 'M' ) ! Miracle wave (has a Hilbert transform?)\r\n ! (peak at 0, support [0, infinity]\r\n A = 1.0 / ( 6.0 * F )\r\n T0 = 6.0 * A\r\n TS = ( T - T0 ) / A\r\n S = 1.0 / ( 1.0 + TS * TS )\r\n ! HS is the Hilbert transform of the time series\r\n ! HS = TS / ( 1.0 + TS * TS )\r\n PulseTitle = 'Miracle wave'\r\n\r\n CASE ( 'G' ) ! Gaussian\r\n ! (peak at 0, support [0, infinity]\r\n ! T0 is the peak time\r\n ! A is the 3dB down time\r\n ! NOTE S(0) = EXP( -NSIG ** 2 )\r\n\r\n NSIG = 3\r\n A = 1.0 / F / ( 2.0 * NSIG )\r\n T0 = NSIG * A\r\n S = EXP( -( ( T - T0 ) / A ) ** 2 )\r\n PulseTitle = 'Gaussian'\r\n CASE ( 'T' ) ! Tone\r\n ! (peak at F, support [0, infinity]\r\n\r\n IF ( T <= 0.4 ) S = SIN( omega * T )\r\n PulseTitle = 'Tone'\r\n CASE ( 'C' ) ! Sinc\r\n ! ( uniform spectrum from [0, F]\r\n\r\n S = SIN( omega * T ) / ( omega * T )\r\n PulseTitle = 'Sinc'\r\n END SELECT\r\n END IF\r\n\r\n SF( :, IT ) = S ! Copy into source vector (waveform duplicated for every source depth)\r\n\r\nEND SUBROUTINE CANS\r\n", "meta": {"hexsha": "175aedc944afe57bb7b672510ce61352fd48538b", "size": 3325, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/tslib/cans.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/cans.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/cans.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": 33.9285714286, "max_line_length": 89, "alphanum_fraction": 0.4568421053, "num_tokens": 1178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102571131691, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.8472453203346906}} {"text": "!\n! Implementation of the iterative Jacobi method.\n!\n! Given a known, diagonally dominant matrix A and a known vector b, we aim to\n! to find the vector x that satisfies the following equation:\n!\n! Ax = b\n!\n! We first split the matrix A into the diagonal D and the remainder R:\n!\n! (D + R)x = b\n!\n! We then rearrange to form an iterative solution:\n!\n! x' = (b - Rx) / D\n!\n! More information:\n! -> https://en.wikipedia.org/wiki/Jacobi_method\n!\n\n! Module which contains the Jacobi solver subrountine\nmodule solve_mod\n\n contains\n\n ! Solve Ax=b according to the Jacobi method\n subroutine solve(N, A, b, x, xtmp, itr, MAX_ITERATIONS, CONVERGENCE_THRESHOLD)\n\n implicit none\n\n ! Input variables\n integer :: N ! Matrix order\n real(kind=8) :: A(N,N) ! The matrix\n real(kind=8) :: b(N) ! The right hand side vector\n real(kind=8), pointer :: x(:) ! Initial solution\n real(kind=8), pointer :: xtmp(:) ! Next solution\n integer :: itr ! Iterations to solve\n integer :: MAX_ITERATIONS ! Iteration limit\n real(kind=8) :: CONVERGENCE_THRESHOLD ! Convergence criteria\n\n ! Local variables\n real(kind=8), pointer :: ptrtmp(:) ! Used for pointer swapping\n integer :: row, col ! Matrix index\n real(kind=8) :: dot\n real(kind=8) :: diff, sqdiff=huge(0.0_8)\n\n ! Loop until converged or maximum iterations reached\n itr = 0\n do while (itr .lt. MAX_ITERATIONS .and. sqrt(sqdiff) .gt. CONVERGENCE_THRESHOLD)\n ! Perfom Jacobi iteration\n do row = 1, N\n dot = 0.0_8\n do col = 1, N\n if (row .ne. col) then\n dot = dot + (A(row,col) * x(col))\n end if\n end do\n xtmp(row) = (b(row) - dot) / A(row,row)\n end do\n\n ! Swap pointers\n ptrtmp => x\n x => xtmp\n xtmp => ptrtmp\n\n ! Check for convergence\n sqdiff = 0.0_8\n do row = 1, N\n diff = xtmp(row) - x(row)\n sqdiff = sqdiff + (diff * diff)\n end do\n\n itr = itr + 1\n end do\n\n end subroutine solve\nend module solve_mod\n\n! Main program\nprogram jacobi\n\n use timer\n use solve_mod ! Include solver (above)\n\n implicit none\n\n ! Solver settings\n integer :: MAX_ITERATIONS=20000\n real(kind=8) :: CONVERGENCE_THRESHOLD=0.0001\n\n ! Timers\n real(kind=8) :: total_start, total_end\n real(kind=8) :: solve_start, solve_end\n\n ! Matrix size\n integer :: N=1000\n\n ! Data arrays\n real(kind=8), allocatable :: A(:,:) ! The matrix\n real(kind=8), allocatable :: b(:) ! The right hand size vector\n real(kind=8), pointer :: x(:) ! Initial solution\n real(kind=8), pointer :: xtmp(:) ! Temporary solution storage\n integer :: itr ! Iteration count\n\n ! Local variables\n integer :: row, col\n real(kind=8) :: rowsum, value\n real(kind=8) :: err, tmp\n\n ! Read in any command line arguments which set problem variables\n call parse_arguments(MAX_ITERATIONS, CONVERGENCE_THRESHOLD, N)\n\n ! Allocate memory\n allocate(A(N,N))\n allocate(b(N))\n allocate(x(N))\n allocate(xtmp(N))\n\n ! Print header\n write(*,\"(A)\") \"------------------------------------\"\n write(*,\"(A,I0,A,I0)\") \"Matrix size: \", N, \" x \", N\n write(*,\"(A,I0)\") \"Maximum iterations: \", MAX_ITERATIONS\n write(*,\"(A,F7.5)\") \"Convergence threshold: \", CONVERGENCE_THRESHOLD\n write(*,\"(A)\") \"------------------------------------\"\n write(*,*)\n\n ! Start the program timer\n call wtime(total_start)\n\n ! Initialize data randomly\n ! A needs to be a diagonally dominant square matrix, so diagonal entries are biased\n do row = 1, N\n rowsum = 0.0_8\n do col = 1, N\n call random_number(value)\n A(row,col) = value\n rowsum = rowsum + value\n end do\n A(row,row) = A(row,row) + rowsum\n call random_number(b(row))\n x(row) = 0.0_8\n end do\n\n ! Run Jacobi solver\n call wtime(solve_start)\n call solve(N, A, b, x, xtmp, itr, MAX_ITERATIONS, CONVERGENCE_THRESHOLD)\n call wtime(solve_end)\n\n ! Check error of final solution\n err = 0.0_8\n do row = 1, N\n tmp = 0.0_8\n do col = 1, N\n tmp = tmp + (A(row,col) * x(col))\n end do\n tmp = b(row) - tmp\n err = err + (tmp*tmp)\n end do\n err = sqrt(err)\n\n ! Stop the program timer\n call wtime(total_end)\n\n ! Print results\n write(*,\"(A,F13.7)\") \"Solution error = \", err\n write(*,\"(A,I0)\") \"Iterations = \", itr\n write(*,\"(A,F10.3)\") \"Total runtime = \", total_end-total_start\n write(*,\"(A,F10.3)\") \"Solver runtime = \", solve_end-solve_start\n if (itr .eq. MAX_ITERATIONS) write(*,\"(A)\") \"WARNING: solution did not converge\"\n write(*,\"(A)\") \"------------------------------------\"\n\n ! Free memory\n deallocate(A, b, x, xtmp)\n\nend program jacobi\n\n! Parse the command line arguments, setting the problem size, etc.\nsubroutine parse_arguments(MAX_ITERATIONS, CONVERGENCE_THRESHOLD, N)\n\n implicit none\n\n integer :: MAX_ITERATIONS\n real(kind=8) :: CONVERGENCE_THRESHOLD\n integer :: N\n\n character(len=32) :: arg\n\n integer :: i=1\n integer :: err\n\n do while (i .le. command_argument_count())\n call get_command_argument(i, arg)\n arg = trim(arg)\n\n if (\"--convergence\" .eq. arg .or. &\n \"-c\" .eq. arg) then\n i = i + 1\n call get_command_argument(i, arg, status=err)\n if (err .ne. 0) then\n write (*,*) \"Error: no convergence threshold given\"\n stop\n end if\n read(arg,*) CONVERGENCE_THRESHOLD\n\n else if (\"--iterations\" .eq. arg .or. &\n \"-i\" .eq. arg) then\n i = i + 1\n call get_command_argument(i, arg, status=err)\n if (err .ne. 0) then\n write (*,*) \"Error: no max iterations given\"\n stop\n end if\n read(arg,*) MAX_ITERATIONS\n\n else if (\"--norder\" .eq. arg .or. &\n \"-n\" .eq. arg) then\n i = i + 1\n call get_command_argument(i, arg, status=err)\n if (err .ne. 0) then\n write (*,*) \"Error: no matrix order given\"\n stop\n end if\n read(arg,*) N\n\n else if (\"--help\" .eq. arg) then\n write(*,\"(A)\") \"Usage: ./jacobi [OPTIONS]\"\n write(*,*)\n write(*,\"(A)\") \"Options:\"\n write(*,\"(2X,A)\") \"-h --help Print this message\"\n write(*,\"(2X,A)\") \"-c --convergence C Set convergence threshold\"\n write(*,\"(2X,A)\") \"-i --iterations I Set maximum number of iterations\"\n write(*,\"(2X,A)\") \"-n --norder N Set maxtrix order\"\n write(*,*)\n stop\n\n else\n write (*,\"(A,A)\") \"Unrecognized argument (try '--help'): \", arg\n stop\n end if\n\n i = i + 1\n end do\nend subroutine parse_arguments\n", "meta": {"hexsha": "973f2d1f60bf9032506e4b3a0d632f621d9e8125", "size": 6680, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/jacobi.f90", "max_stars_repo_name": "PourroyJean/openmp-for-cs", "max_stars_repo_head_hexsha": "d5f1dea5b1aedb8a059c5efaf0c14585886c9e88", "max_stars_repo_licenses": ["MIT"], "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/jacobi.f90", "max_issues_repo_name": "PourroyJean/openmp-for-cs", "max_issues_repo_head_hexsha": "d5f1dea5b1aedb8a059c5efaf0c14585886c9e88", "max_issues_repo_licenses": ["MIT"], "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/jacobi.f90", "max_forks_repo_name": "PourroyJean/openmp-for-cs", "max_forks_repo_head_hexsha": "d5f1dea5b1aedb8a059c5efaf0c14585886c9e88", "max_forks_repo_licenses": ["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.3770491803, "max_line_length": 85, "alphanum_fraction": 0.572005988, "num_tokens": 1979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088043, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.8472253597355165}} {"text": "! Even Fibonacci numbers\n! Problem 2\n! Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:\n!\n! 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...\n!\n! By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.\n\n! Answer: 4613732\n\nprogram ex002\n implicit none\n\n integer, parameter :: num = 4000000\n integer(8) :: res = 0\n\n call iterate_fib(num, sum_if_even)\n\n print *, 'Answer:', res\ncontains\n subroutine iterate_fib(limit, callback)\n implicit none\n\n integer, intent(in) :: limit\n interface\n subroutine callback(arg)\n integer, intent(in) :: arg\n end subroutine callback\n end interface\n integer :: f1 = 0, f2 = 1\n\n do\n f1 = f1 + f2\n if (f1 > limit) exit\n call callback(f1)\n\n f2 = f1 + f2\n if (f1 > limit) exit\n call callback(f2)\n end do\n end subroutine iterate_fib\n\n subroutine sum_if_even(n)\n implicit none\n\n integer, intent(in) :: n\n\n if (mod(n, 2) == 0) res = res + n\n end subroutine sum_if_even\nend program ex002\n", "meta": {"hexsha": "9b79186a513072f3329adae325ecc234442093a8", "size": 1206, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex002/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/ex002/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/ex002/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.6470588235, "max_line_length": 142, "alphanum_fraction": 0.6194029851, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.8976952941600964, "lm_q1q2_score": 0.8468386728392505}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_scalar_random_normal\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine provides a pseudo-random complex number independent, standard,\n! normally distributed (expected value 0, standard deviation 1). The routine\n! generates two uniformly distributed random numbers using Fortran's built-in\n! routine and then uses the Box-Muller transform. \n! Call u_randomseed_initialize(INFO) first to set the seed of the number \n! generator.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! OUTPUT VARIABLES:\n!\n! RE REAL(8) \n! real part of random complex number \n!\n! CO REAL(8) \n! complex part of random complex number \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_scalar_random_normal(RE, CO)\n\n implicit none\n \n ! input variables\n real(8), intent(inout) :: RE, CO\n\n ! compute variables\n double precision :: u,v,s,pi = EISCOR_DBL_PI\n integer :: ii\n \n do ii = 1, 100\n call random_number(u)\n call random_number(v)\n s = u**2 + v**2\n \n ! Box-Muller transform\n if ((s > 0d0) .AND. (s < 1d0)) then\n RE = dcos(2.d0*pi*u)*dsqrt(-2.d0*dlog(v))\n CO = dsin(2.d0*pi*u)*dsqrt(-2.d0*dlog(v))\n exit\n end if\n end do\n\nend subroutine z_scalar_random_normal\n", "meta": {"hexsha": "6f141846aea9cf60a7dea9687092c272dfdc5cd1", "size": 1499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_scalar_random_normal.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_random_normal.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_random_normal.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": 29.3921568627, "max_line_length": 79, "alphanum_fraction": 0.4976651101, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342024724487, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.845702208863441}} {"text": "program problem_7\n implicit none\n logical :: isPrime\n integer :: i\n integer :: counter\n integer :: limit\n integer :: num\n\n counter = 1\n limit = 10001\n num = 3\n\n do while (counter .LT. limit)\n if (isPrime(num)) then\n counter = counter + 1\n endif\n num = num + 2\n enddo\n\n print *, num - 2\n print *, counter\n\nend program problem_7\n\nlogical function isPrime(number)\n implicit none\n integer :: number\n integer :: i\n\n if ((number .EQ. 0) .OR. (number .EQ. 1) .OR. ((number .NE. 2) .AND. (modulo(number, 2) .EQ. 0))) then\n isPrime = .FALSE.\n return\n endif\n\n do i=3, number / 3, 2\n if (modulo(number, i) .EQ. 0) then\n isPrime = .FALSE.\n return\n endif\n enddo\n\n isPrime = .TRUE.\n return\n \nend function isPrime", "meta": {"hexsha": "fd0570c830ca80e5b6bd2f7f75ad57cd83783d8f", "size": 849, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_7/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_7/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_7/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": 18.8666666667, "max_line_length": 106, "alphanum_fraction": 0.5347467609, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8887587942290706, "lm_q1q2_score": 0.8453360150429884}} {"text": "PROGRAM A3Q2\r\n!--\r\n!Finds values of x where f(x)(x^2-2x-1) = 0 using the secant method. \r\n!--\r\nIMPLICIT NONE\r\nREAL :: a, b, eps, root\r\nINTEGER :: limit, iter\r\n\r\neps = .001\r\nlimit = 50\r\niter = 0\r\nPRINT *, 'Attempts to solve f(x) = x^2-2x-1 for f(x)=0 using the secant method.'\r\nPRINT *, 'Precision:', eps, 'loop limit:', limit\r\nDO\r\n\tPRINT *, 'Enter your values for a and b. (enter 0 0 to stop)'\r\n READ *, a, b\r\n IF (a .eq. 0.0 .and. b .eq. 0.0) STOP\r\n root = Secant(a, b, eps, limit, iter)\r\n PRINT *, 'root:', root, 'iterations:', iter\r\nEND DO\r\n\r\nCONTAINS\r\n!- Secant method\r\nREAL FUNCTION Secant(a, b, eps, limit, iter)\r\n\tREAL, INTENT(IN) :: a, b, eps\r\n INTEGER, INTENT(IN) :: limit\r\n INTEGER, INTENT(OUT) :: iter\r\n REAL :: x, x0, x1, fraction\r\n \r\n fraction = 0\r\n iter = 0\r\n x = 0\r\n\tx0 = a\r\n x1 = b\r\n fraction = fun(x1) / (fun(x1) - fun(x0))\r\n DO WHILE (abs(x0-x1) .gt. eps .and. iter .lt. limit)\r\n \tx = x1 - (x1 - x0) * fraction\r\n x0 = x1\r\n x1 = x\r\n fraction = fun(x1) / (fun(x1) - fun(x0))\r\n iter = iter + 1\r\n ! Print additional information\r\n ! PRINT *, x, x0, x1, iter, abs(x0-x1)\r\n END DO\r\n Secant = x\r\n\r\nEND FUNCTION Secant\r\n!- fun(x) = x^2-2x-1\r\nREAL FUNCTION fun(x)\r\n REAL, INTENT(IN) :: x\r\n \r\n\tfun = (x - 2) * x - 1\r\n \r\nEND FUNCTION fun\r\nEND PROGRAM A3Q2", "meta": {"hexsha": "b3c97f2cf77f8bc6a0fe7260901f1e2d373fb544", "size": 1363, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 3/A3Q2.f90", "max_stars_repo_name": "Chris-Drury/COMP3731", "max_stars_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 3/A3Q2.f90", "max_issues_repo_name": "Chris-Drury/COMP3731", "max_issues_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 3/A3Q2.f90", "max_forks_repo_name": "Chris-Drury/COMP3731", "max_forks_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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.7818181818, "max_line_length": 81, "alphanum_fraction": 0.5370506236, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966101527047, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.8448624030281547}} {"text": "! -*- Mode: Fortran90; -*-\n!-----------------------------------------------------------------\n! Daniel R. Reynolds\n! SMU Mathematics\n! Math 4370/6370\n! 7 February 2015\n!=================================================================\n\n\nprogram ComputePi\n !-----------------------------------------------------------------\n ! Description: \n ! Computes pi through numerical integration via\n ! pi = 4*int_0^1 1/(1+x^2) dx\n ! We use a simple midpoint rule for integration, over \n ! subintervals of fixed size 1/n, where n is a user-input \n ! parameter.\n !-----------------------------------------------------------------\n !======= Inclusions ===========\n\n !======= Declarations =========\n implicit none\n integer :: n\n integer :: i\n double precision :: pi, h, x, f, a, stime, ftime\n double precision, parameter :: pi_true = 3.14159265358979323846d0\n\n !======= Internals ============\n \n ! set the integrand function\n f(a) = 4.d0 / (1.d0 + a*a)\n\n ! input the number of intervals\n write(*,*) 'Enter the number of intervals (0 quits):'\n read(*,*) n\n if (n < 1) then\n stop\n endif\n\n ! start timer\n call get_time(stime)\n\n ! set subinterval width\n h = 1.d0/n\n\n ! perform integration over n intervals\n pi = 0.d0\n do i=1,n,1\n x = h*(i - 0.5d0)\n pi = pi + h*f(x)\n enddo\n\n ! stop timer\n call get_time(ftime)\n\n ! output computed value and error\n write(*,*) ' computed pi =',pi\n write(*,*) ' true pi =',pi_true\n write(*,*) ' error =',pi_true - pi\n write(*,*) ' runtime =',ftime-stime\n \n\nend program ComputePi\n!=================================================================\n", "meta": {"hexsha": "d228875a2969200c396cd4039fef4a8e04883aea", "size": 1643, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi/pi_comp.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": "pi/pi_comp.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": "pi/pi_comp.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": 25.2769230769, "max_line_length": 68, "alphanum_fraction": 0.4650030432, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381606, "lm_q2_score": 0.9149009567332237, "lm_q1q2_score": 0.8444894183978024}} {"text": "program nmdf\n use tools\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 ! points -- 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 ! output:\n ! res -- 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 ! - used module \"tools\"\n ! env details:\n ! compiler -- gfortran v10.2.0\n ! OS -- macOS 12.0 x86_64F\n ! Kernel -- Darwin 21.0.0\n ! ----------------------------------------------------------------\n implicit none\n integer, parameter :: points = 8\n real(dp), dimension(points) :: x, y\n real(dp) :: x_point, res\n integer :: i\n character(len=10) :: poly\n\n ! given data points\n data(x(i), i=1, 8)/1.21, 1.31, 1.41, 1.51, 1.61, 1.71, 1.81, 1.91/\n data(y(i), i=1, 8)/4.43, 6.84, 10.06, 12.67, 15.73, 19.87, 21.86, 24.61/\n\n x_point = 1.61 ! the calculation point\n res = 0.0\n\n call neum_diff(points, x, y, x_point, poly, res)\n\n ! result printing\n print *, ''\n print *, 'result:'\n write (*, form_result2c) poly, '-- interpolation polynomial'\n write (*, form_result2r) x_point, '-- given point'\n write (*, form_result2r) res, '-- value of derivative'\nend program nmdf\n", "meta": {"hexsha": "ac244ef7a6286215db1594f3f170a5ef028542d7", "size": 1705, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "programs/numerical_diff.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/numerical_diff.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/numerical_diff.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": 34.7959183673, "max_line_length": 74, "alphanum_fraction": 0.5747800587, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132747, "lm_q2_score": 0.8918110425624792, "lm_q1q2_score": 0.8441853660245049}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0), m1 = 2.d0, m2 = 1.d0\n real(dp) :: k, omega1, omega2, dk\n\n dk = 1.d-2\n ! reduced zone scheme\n open(unit = 1, file = '1-ReducedZoneScheme.txt', status = 'unknown')\n k = -pi\n do while (k <= pi)\n ! acoustic mode\n omega1 = sqrt(1.d0 / m1 / m2 * ((m1 + m2) - sqrt((m1 + m2)**2 - 4.d0 * m1 * m2 * sin(k / 2.d0)**2)))\n ! optical mode\n omega2 = sqrt(1.d0 / m1 / m2 * ((m1 + m2) + sqrt((m1 + m2)**2 - 4.d0 * m1 * m2 * sin(k / 2.d0)**2)))\n write(1,'(3f20.8)') k, omega1, omega2\n k = k + dk\n end do\n close(1)\n\n ! extended zone scheme\n ! optical mode\n open(unit = 2, file = '1-ExtendedZoneSchemeOpticalMode.txt', status = 'unknown')\n k = 0.d0\n do while (k <= pi)\n omega1 = sqrt(1.d0 / m1 / m2 * ((m1 + m2) + sqrt((m1 + m2)**2 - 4.d0 * m1 * m2 * sin((-2.d0 * pi - k) / 2.d0)**2)))\n omega2 = sqrt(1.d0 / m1 / m2 * ((m1 + m2) + sqrt((m1 + m2)**2 - 4.d0 * m1 * m2 * sin((pi + k) / 2.d0)**2)))\n write(2,'(4f20.8)') -2.d0 * pi + k, omega1, pi + k, omega2\n k = k + dk\n end do\n close(2)\n ! acoustic mode\n open(unit = 3, file = '1-ExtendedZoneSchemeAcousticMode.txt', status = 'unknown')\n k = -pi\n do while (k <= pi)\n omega1 = sqrt(1.d0 / m1 / m2 * ((m1 + m2) - sqrt((m1 + m2)**2 - 4.d0 * m1 * m2 * sin(k / 2.d0)**2)))\n write(3,'(2f20.8)') k, omega1\n k = k + dk\n end do\n close(3)\nend program main\n", "meta": {"hexsha": "db8135ba4d9ea105f6176bb6c3e24101f0e49427", "size": 1558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-6/1-omega-k.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/1-omega-k.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/1-omega-k.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": 37.0952380952, "max_line_length": 123, "alphanum_fraction": 0.4955070603, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779946215714, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.8440659459560673}} {"text": "! Objetivo: Calcular todos os numeros primos ate um limite superior.\n! Metodo: Crivo de Eratostenes.\n! Autor: I.F.F. dos Santos\n! Exemplo de compilacao e execucao no linux:\n! gfortran crivo.f90 -o crivo && ./crivo\nPROGRAM crivo\n ! O que segue serve somente para testar a rotina crivo_de_eratostenes().\n ! O verdadeiro algoritmo eh a subrotina em CONTAINS.\n ! Declaracoes\n IMPLICIT none\n INTEGER :: limite_superior\n ! Comandos executaveis\n PRINT *, \"Bem vindo ao programa Crivo!\"\n PRINT *, \"Por favor, digite o maior numero da lista onde serao buscados os &\n &numeros primos:\"\n READ *, limite_superior\n ! Chamando a rotina para o Crivo\n CALL crivo_de_eratostenes(limite_superior)\n \nCONTAINS\n SUBROUTINE crivo_de_eratostenes(limite_superior)\n IMPLICIT none\n INTEGER, intent(IN) :: limite_superior\n INTEGER :: numero, multiplos\n LOGICAL :: lista(limite_superior)\n\n ! Os elementos da lista marcados como falsos,\n ! de certeza nao sao primos\n lista = .true.\n\n PRINT *, \"Os numeros primos ate\", limite_superior, \"sao\"\n\n DO numero = 2, limite_superior\n IF( lista(numero) )THEN\n PRINT *, numero ! Escreve os numeros nao \"riscados\" da lista\n DO multiplos = numero + numero, limite_superior, numero\n lista(multiplos) = .false. ! \"Risca\" os multiplos deste da lista\n END DO\n END IF\n END DO\n END SUBROUTINE\nEND PROGRAM crivo\n", "meta": {"hexsha": "6988620e7562c6c2d736503dcf87bbd0bed1f346", "size": 1474, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "programas/crivo.f90", "max_stars_repo_name": "ismaeldamiao/Apostila_de_IFC", "max_stars_repo_head_hexsha": "57350842ec35b28ced2557f9587c58c5da230910", "max_stars_repo_licenses": ["MIT"], "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/crivo.f90", "max_issues_repo_name": "ismaeldamiao/Apostila_de_IFC", "max_issues_repo_head_hexsha": "57350842ec35b28ced2557f9587c58c5da230910", "max_issues_repo_licenses": ["MIT"], "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/crivo.f90", "max_forks_repo_name": "ismaeldamiao/Apostila_de_IFC", "max_forks_repo_head_hexsha": "57350842ec35b28ced2557f9587c58c5da230910", "max_forks_repo_licenses": ["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.2790697674, "max_line_length": 79, "alphanum_fraction": 0.6689280868, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.9032942112597332, "lm_q1q2_score": 0.8440337479532597}} {"text": " INTEGER*8 FUNCTION SUMI(N)\t!Sums the integers 1 to N inclusive.\nCalculates as per the young Gauss: N*(N + 1)/2 = 1 + 2 + 3 + ... + N.\n INTEGER*8 N\t!The number. Possibly large.\n IF (MOD(N,2).EQ.0) THEN\t!So, I'm worried about overflow with N*(N + 1)\n SUMI = N/2*(N + 1)\t\t!But since N is even, N/2 is good.\n ELSE\t\t\t!Otherwise, if N is odd,\n SUMI = (N + 1)/2*N\t\t!(N + 1) must be even.\n END IF\t\t\t!Either way, the /2 reduces the result.\n END FUNCTION SUMI\t\t!So overflow of intermediate results is avoided.\n\n INTEGER*8 FUNCTION SUMF(N,F)\t!Sum of numbers up to N divisible by F.\n INTEGER*8 N,F\t\t!The selection.\n INTEGER*8 L\t\t!The last in range. N itself is excluded.\n INTEGER*8 SUMI\t\t!Known type of the function.\n L = (N - 1)/F\t\t!Truncates fractional parts.\n SUMF = F*SUMI(L)\t!3 + 6 + 9 + ... = 3(1 + 2 + 3 + ...)\n END FUNCTION SUMF\t\t!Could just put SUMF = F*SUMI((N - 1)/F).\n\n INTEGER*8 FUNCTION SUMBFI(N)\t!Brute force and ignorance summation.\n INTEGER*8 N\t!The number.\n INTEGER*8 I,S\t!Stepper and counter.\n S = 0\t\t!So, here we go.\n DO I = 3,N - 1\t!N itself is not a candidate.\n IF (MOD(I,3).EQ.0 .OR. MOD(I,5).EQ.0) S = S + I\t!Whee!\n END DO\t\t!On to the next.\n SUMBFI = S\t\t!The result.\n END FUNCTION SUMBFI\t!Oh well, computers are fast these days.\n\n INTEGER*8 SUMF,SUMBFI\t!Known type of the function.\n INTEGER*8 N\t!The number.\n WRITE (6,*) \"Sum multiples of 3 and 5 up to N\"\n 10 WRITE (6,11)\t\t!Ask nicely.\n 11 FORMAT (\"Specify N: \",$)\t!Obviously, the $ says 'stay on this line'.\n READ (5,*) N\t\t!If blank input is given, further input will be requested.\n IF (N.LE.0) STOP\t\t!Good enough.\n WRITE (6,*) \"By Gauss:\",SUMF(N,3) + SUMF(N,5) - SUMF(N,15)\n WRITE (6,*) \"BFI sum :\",SUMBFI(N)\t\t!This could be a bit slow.\n GO TO 10\t\t\t!Have another go.\n END\t!So much for that.\n", "meta": {"hexsha": "197b54eec1f6ed073e12e0f3e50df2c0c7ad00b3", "size": 1963, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sum-multiples-of-3-and-5/Fortran/sum-multiples-of-3-and-5.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/Sum-multiples-of-3-and-5/Fortran/sum-multiples-of-3-and-5.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/Sum-multiples-of-3-and-5/Fortran/sum-multiples-of-3-and-5.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": 49.075, "max_line_length": 78, "alphanum_fraction": 0.5751400917, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8962513800615312, "lm_q1q2_score": 0.8439588428274832}} {"text": "MODULE precision\n ! dp = double precision\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\nPROGRAM Bisection_Method\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: x0, x1, x2, f0, f1, f2, error, root\n WRITE(*, *) \"Enter value of interval (a and b)\"\n ! For this question enter [0.5, 2.0]\n READ *, x1, x2\n \n error = 1e-6\n f1 = Func(x1)\n f2 = Func(x2)\n\n IF (f1*f2 .GT. 0.0) THEN\n WRITE(*, *) \"Given interval do not bracket any root\"\n RETURN\n ENDIF\n\n DO\n x0 = (x1 + x2) / 2.0_dp\n f0 = Func(x0)\n\n IF (f0 .EQ. 0.0) THEN\n root = x0\n WRITE(*, *) \"Root is: \", root\n RETURN\n ENDIF\n\n IF(f1 * f0 .LT. 0.0_dp) THEN \n x2 = x0 \n ELSE \n x1 = x0 \n ENDIF\n\n IF (abs((x2 - x1)/x2) .LT. error) THEN \n root = (x1 + x2) / 2.0_dp\n WRITE(*, *) \"Root is: \", root\n RETURN\n ENDIF\n ENDDO \n\n CONTAINS\n REAL(KIND = dp) FUNCTION Func(x)\n USE precision\n IMPLICIT NONE \n REAL(KIND = dp):: x\n Func = x**3 - 2 * Sin(x)\n RETURN \n END FUNCTION Func\n\nEND PROGRAM Bisection_Method\n", "meta": {"hexsha": "b3236bff19c97c66b4fca5c4ca3367d459464a07", "size": 1223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Roots of Nonlinear Equation/Bisection Method.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": "Roots of Nonlinear Equation/Bisection Method.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": "Roots of Nonlinear Equation/Bisection Method.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.4561403509, "max_line_length": 60, "alphanum_fraction": 0.4930498774, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.8439588340211354}} {"text": " ! calculate inverse matrix\n SUBROUTINE calcInverse(dim,mat,invMat)\n IMPLICIT NONE\n INTEGER dim,i,j\n DOUBLE PRECISION mat(dim,dim),invMat(dim,dim),bufMat(dim,dim),buf\n bufMat(:,:) = mat(:,:)\n invMat(:,:) = 0.0D0\n DO i=1,dim\n invMat(i,i) = 1.0D0\n END DO\n DO i=1,dim\n buf = 1.0D0/mat(i,i)\n mat(i,:) = mat(i,:)*buf\n invMat(i,:) = invMat(i,:)*buf\n DO j=1,dim\n IF (i/=j) THEN\n buf = mat(j,i)\n mat(j,:) = mat(j,:) - mat(i,:)*buf\n invMat(j,:) = invMat(j,:) - invMat(i,:)*buf\n END IF\n END DO\n END DO\n mat(:,:) = bufMat(:,:)\n RETURN\n END SUBROUTINE calcInverse\n\n\n ! calculate invariants of stress tensor\n SUBROUTINE calcInvariants(stress,invariants)\n DOUBLE PRECISION stress(6),invariants(2)\n invariants(1) = (stress(1) + stress(2) + stress(3))/3.0D0\n invariants(2) = (stress(4)**2 + stress(5)**2 + stress(6)**2 - \n & stress(1)*stress(2) - stress(2)*stress(3) - \n & stress(3)*stress(1))/3.0D0\n RETURN\n END SUBROUTINE calcInvariants\n\n\n ! calculate principal value of matrix\n SUBROUTINE calcPrincipal(mat,principal,invariants)\n DOUBLE PRECISION mat(3,3),principal(3),invariants(3),radius,\n & theta,PI\n PI = acos(-1.0D0)\n principal(:) = 0.0D0\n invariants(:) = 0.0D0\n DO i=1,3\n invariants(1) = invariants(1) + mat(i,i)/3.0D0\n END DO\n invariants(2) = (mat(2,3)**2 + mat(3,1)**2 + mat(1,2)**2 - \n & mat(2,2)*mat(3,3) - mat(3,3)*mat(1,1) - mat(1,1)*mat(2,2))/3.0D0\n invariants(3) = (2*mat(1,2)*mat(2,3)*mat(3,1) + \n & mat(1,1)*mat(2,2)*mat(3,3) - mat(1,1)*mat(2,3)**2 - \n & mat(2,2)*mat(3,1)**2 - mat(3,3)*mat(1,2)**2)/2.0D0\n radius = 2*sqrt(invariants(1)**2 + invariants(2))\n theta = acos(((2*invariants(1)**3 + 3*invariants(1)*\n & invariants(2) + 2*invariants(3))/2.0D0)/\n & sqrt((invariants(1)**2 + invariants(2))**3))\n principal(1) = radius*cos(theta/3.0D0) + invariants(1)\n principal(2) = radius*cos((theta + 4*PI)/3.0D0) + invariants(1)\n principal(3) = radius*cos((theta + 2*PI)/3.0D0) + invariants(1)\n RETURN\n END SUBROUTINE calcPrincipal\n\n\n ! enable using same random seed, this func is just a memo\n FUNCTION random()\n DOUBLE PRECISION x\n INTEGER seedsize,seed\n ALLOCATABLE seed(:)\n CALL RANDOM_SEED(size=seedsize)\n ALLOCATE(seed(seedsize))\n CALL RANDOM_SEED(get=seed)\n CALL RANDOM_NUMBER(x)\n WRITE(*,*) x\n ! CALL sleep(1)\n CALL RANDOM_SEED(put=seed)\n CALL RANDOM_NUMBER(x)\n WRITE(*,*) x\n END FUNCTION random\n\n\n ! sort list in descending order\n RECURSIVE SUBROUTINE quickSort(vec, first, last)\n IMPLICIT NONE\n INTEGER first,last,i,j\n DOUBLE PRECISION vec(*),x,t \n x = vec( (first+last) / 2 )\n i = first\n j = last\n DO\n DO WHILE (vec(i) > x)\n i=i+1\n END DO\n DO WHILE (x > vec(j))\n j=j-1\n END DO\n IF (i >= j) EXIT\n t = vec(i)\n vec(i) = vec(j)\n vec(j) = t\n i=i+1\n j=j-1\n END DO\n IF (first < i - 1) THEN\n CALL quicksort(vec, first, i - 1)\n END IF\n IF (j + 1 < last) THEN\n CALL quicksort(vec, j + 1, last)\n END IF\n END SUBROUTINE quickSort\n", "meta": {"hexsha": "2473fdae185d658974cbbf12cd5953c4ec9f49a4", "size": 3411, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src_fortran/Lib.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/Lib.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/Lib.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": 30.7297297297, "max_line_length": 72, "alphanum_fraction": 0.5321020229, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.843000045080689}} {"text": "program composite_trapezoidal\n ! Author : Anantha S Rao (Reg no : 20181044)\n ! Program to evaluate the integral I = Int_a^b Gaus(0,1) \n implicit none\n real*8,external::func\n ! An external function f in double precision\n\n real*8::a,b,h,pi,trapezoidal_integral\n ! a : Lower limit of the integral\n ! b : Upper limit of the integral\n ! h : bin size\n ! trapezoidal_integral : Value of the integral using trapezoidal technique\n\n integer::n,i\n ! n : number of bins \n ! i : counter\n \n pi= 2.0d0*ASIN(1.0d0)\n n = 1000\n print 10, n\n 10 format(\"Welcome to this program. &\n & This program does integration on I= Int_a^b Gaus(0,1) using trapezoidal rule with n=\",i5,\" bins\" )\n\n a = -3\n b = 3\n h=(b-a)/real(n) ! size of each bin\n trapezoidal_integral=(h/2)*(func(a)+func(b))\n do i=1,n-1\n trapezoidal_integral=trapezoidal_integral+h*func(a+i*h)\n end do\n print *, \"The integrated value using trapezoidal rule in (-3,3) is:\",trapezoidal_integral\n\n a = -5\n b = 5\n h=(b-a)/real(n) ! size of each bin\n trapezoidal_integral=(h/2)*(func(a)+func(b))\n do i=1,n-1\n trapezoidal_integral=trapezoidal_integral+h*func(a+i*h)\n end do\n print *, \"The integrated value using trapezoidal rule in (-5,5) is:\",trapezoidal_integral\n\nend program composite_trapezoidal\n\nreal*8 function func(x)\n implicit none\n real*8::x, pi\n pi= 2.0d0*ASIN(1.0d0)\n func= (1.0d0/SQRT(2.0d0*pi))*EXP(-(x*x)/2.0d0)\nend function\n", "meta": {"hexsha": "02f769d3ea658bb35c149befd2196fb7b45005a9", "size": 1506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn01_solns/Assgn01_C_sourcecode.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/assgn01_solns/Assgn01_C_sourcecode.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/assgn01_solns/Assgn01_C_sourcecode.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": 30.12, "max_line_length": 109, "alphanum_fraction": 0.6381142098, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8918110375304408, "lm_q1q2_score": 0.8427567143077944}} {"text": "module numinteg\n\tinterface\t\n\t\tfunction simpson(H, FI) result (S)\n\t\t\tuse kind_defs\n\t\t\timplicit none\n\t\t\treal(dbl), intent(in) :: H\n\t\t\treal(dbl), intent(in) :: FI(:)\n\t\t\treal(dbl) :: S\n\t\tend function\n\tend interface\nend module\n\n! Subroutine for integration over f(x) with the Simpson rule.\n! FI: integrand f(x); H: interval; S: integral. Copyright (c) Tao Pang 1997.\nfunction simpson(H, FI) result (S)\n\tuse kind_defs\n\timplicit none\n\treal(dbl), intent(in) :: H\n\treal(dbl), intent(in) :: FI(:)\n\treal(dbl) :: S\n\tinteger :: i, N\n\treal(dbl) :: S0,S1,S2\n\n\tN = size(FI)\n\tS = 0.0_dbl\n\tS0 = 0.0_dbl\n\tS1 = 0.0_dbl\n\tS2 = 0.0_dbl\n\tdo i = 2,N-1,2\n\t\tS1 = S1 + FI(i-1)\n\t\tS0 = S0 + FI(i)\n\t\tS2 = S2 + FI(i+1)\n\tenddo\n\tS = H*(S1+4.0_dbl*S0+S2)/3.0_dbl\n\t\n\t! If N is even, add the last slice separately\n\tif (mod(N,2) .eq. 0) then\n\t\tS = S + H*(5.0_dbl*FI(N)+8.0_dbl*FI(N-1)-FI(N-2))/12.0_dbl\n\tendif\nend function simpson\n", "meta": {"hexsha": "47e415c07d5897f4ad7e569b528cbc0964b53086", "size": 894, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/integrate.f90", "max_stars_repo_name": "rhandberg/timeseries", "max_stars_repo_head_hexsha": "92fc61c0a5b014363544c4ccd762077c9e1ba43e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-02T19:38:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-10T09:45:04.000Z", "max_issues_repo_path": "src/integrate.f90", "max_issues_repo_name": "rhandberg/timeseries", "max_issues_repo_head_hexsha": "92fc61c0a5b014363544c4ccd762077c9e1ba43e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-03-18T09:58:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-15T11:36:30.000Z", "max_forks_repo_path": "src/integrate.f90", "max_forks_repo_name": "rhandberg/timeseries", "max_forks_repo_head_hexsha": "92fc61c0a5b014363544c4ccd762077c9e1ba43e", "max_forks_repo_licenses": ["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.8048780488, "max_line_length": 76, "alphanum_fraction": 0.6196868009, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.8918110368115781, "lm_q1q2_score": 0.8427567122469543}} {"text": "module quadrature\n \n implicit none\n\n integer :: quadrature_type = 1\n real(kind=8) :: quadrature_relerr = 1e-6\n integer :: gaussorder = 12\n\n contains\n\n function gaussquad(func,n,a,b,tid) result(z)\n !\n ! This function computes the indefinite integral of the function func\n ! from a to b using an n-point Gauss-Legendre quadrature algorithm.\n !\n ! This function is thread-safe. \n !\n ! The function func must be an external function which takes two arguments:\n ! func(x, tid)\n ! where x is a ready kind-8 and tid is an integer. Typically tid is used\n ! for accessing data unique to a thread, available in shared memory.\n !\n ! This function is modified from its original form found on Rosettacode.org:\n ! https://rosettacode.org\n ! https://rosettacode.org/wiki/Numerical_integration/Gauss-Legendre_Quadrature\n ! which is freely available under GNU free documentation license 1.2.\n !\n implicit none\n \n real (kind=8), external :: func\n integer, parameter :: p=8\n integer :: n\n real(kind=p), parameter :: pi = 4*atan(1._p)\n real(kind=p) :: r(2, n), x, f, df, dx\n integer :: i, iter, k\n real (kind = p) :: pc0(n+1), pc1(n+1), pctmp(n+1)\n real(kind=p) :: z, a, b, zsum, vv\n integer tid\n \n pc0(1) = 1._p\n pc1(1:2) = [1._p, 0._p]\n do k = 2, n\n pctmp(1:k+1) = ((2*k-1)*[pc1(1:k),0._p]-(k-1)*[0._p, 0._p,pc0(1:k-1)])/k\n pc0 = pc1; pc1 = pctmp\n end do\n do i = 1, n\n x = cos(pi*(i-0.25_p)/(n+0.5_p))\n do iter = 1, 10\n f = pc1(1); df = 0._p\n do k = 2, size(pc1)\n df = f + x*df\n f = pc1(k) + x * f\n end do\n dx = f / df\n x = x - dx\n if (abs(dx)<10*epsilon(dx)) exit\n end do\n r(1,i) = x\n r(2,i) = 2/((1-x**2)*df**2)\n end do\n \n zsum = 0._p\n do i = 1, n\n vv = (a+b)/2 + r(1,i)*(b-a)/2\n zsum = zsum + r(2,i) * func(vv, tid)\n end do\n \n z = (b-a)/2 * zsum\n \n end function\n\n function g8(func, x, h, tid)\n \n implicit none\n real ( kind = 8 ), external :: func\n real ( kind = 8 ) h\n real ( kind = 8 ) x\n integer tid\n \n real (kind = 8 ) :: g8\n \n real ( kind = 8 ) :: w1 = 3.62683783378361983D-01\n real ( kind = 8 ) :: w2 = 3.13706645877887287D-01\n real ( kind = 8 ) :: w3 = 2.22381034453374471D-01\n real ( kind = 8 ) :: w4 = 1.01228536290376259D-01\n real ( kind = 8 ) :: x1 = 1.83434642495649805D-01\n real ( kind = 8 ) :: x2 = 5.25532409916328986D-01\n real ( kind = 8 ) :: x3 = 7.96666477413626740D-01\n real ( kind = 8 ) :: x4 = 9.60289856497536232D-01\n \n g8 = h * ( ( & \n w1 * ( func ( x - x1 * h, tid ) + func ( x + x1 * h, tid ) ) & \n + w2 * ( func ( x - x2 * h, tid ) + func ( x + x2 * h, tid ) ) ) & \n + ( w3 * ( func ( x - x3 * h, tid ) + func ( x + x3 * h, tid ) ) & \n + w4 * ( func ( x - x4 * h, tid ) + func ( x + x4 * h, tid ) ) ) )\n \n end function g8 \n \n subroutine gaus8_threadsafe ( func, a, b, err, result, ierr, tid )\n \n !*****************************************************************************80\n !\n !! GAUS8 estimates the integral of a function.\n ! Modified by O. Gorton c. May 2021 for use with openMP.\n !\n ! Discussion:\n !\n ! GAUS8 integrates real functions of one variable over finite\n ! intervals using an adaptive 8-point Legendre-Gauss\n ! algorithm.\n !\n ! GAUS8 is intended primarily for high accuracy integration or\n ! integration of smooth functions.\n !\n ! Modified:\n !\n ! 30 October 2000\n !\n ! Author:\n !\n ! Ron Jones,\n ! Sandia National Laboratory,\n ! Los Alamos, New Mexico\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 ! Parameters:\n !\n ! Input, real ( kind = 8 ), external FUNC, name of external function to\n ! be integrated. This name must be in an external statement in the\n ! calling program. FUNC must be a function of one real argument. The value\n ! of the argument to FUNC is the variable of integration\n ! which ranges from A to B.\n !\n ! Input, real ( kind = 8 ) A, the lower limit of integration.\n !\n ! Input, real ( kind = 8 ) B, the upper limit of integration.\n !\n ! Input/output, real ( kind = 8 ) ERR.\n ! On input, ERR is a requested pseudorelative error\n ! tolerance. Normally pick a value of ABS ( ERR ) so that\n ! STOL < ABS ( ERR ) <= 1.0D-3 where STOL is the single precision\n ! unit roundoff.\n ! RESULT will normally have no more error than\n ! ABS ( ERR ) times the integral of the absolute value of\n ! FUN(X). Usually, smaller values for ERR yield more\n ! accuracy and require more function evaluations.\n ! A negative value for ERR causes an estimate of the\n ! absolute error in RESULT to be returned in ERR. Note that\n ! ERR must be a variable (not a constant) in this case.\n ! Note also that the user must reset the value of ERR\n ! before making any more calls that use the variable ERR.\n ! On output, ERR will be an estimate of the absolute error\n ! in RESULT if the input value of ERR was negative. ERR is\n ! unchanged if the input value of ERR was non-negative.\n ! The estimated error is solely for information to the user\n ! and should not be used as a correction to the computed integral.\n !\n ! Output, real ( kind = 8 ) RESULT, the computed value of the integral.\n !\n ! Output, integer ( kind = 4 ) IERR, a status code.\n ! Normal Codes:\n ! 1 RESULT most likely meets requested error tolerance, or A = B.\n ! -1 A and B are too nearly equal to allow normal\n ! integration. RESULT is set to zero.\n ! Abnormal Code:\n ! 2 RESULT probably does not meet requested error tolerance.\n !\n ! input, real arg : extra argument for func\n implicit none\n \n real ( kind = 8 ) a\n real ( kind = 8 ) aa(30)\n real ( kind = 8 ) ae\n real ( kind = 8 ) anib\n real ( kind = 8 ) area\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) ce\n real ( kind = 8 ) ee\n real ( kind = 8 ) ef\n real ( kind = 8 ) eps\n real ( kind = 8 ) err\n real ( kind = 8 ) est\n real ( kind = 8 ), external :: func\n real ( kind = 8 ) gl\n real ( kind = 8 ) glr\n real ( kind = 8 ) gr(30)\n real ( kind = 8 ) hh(30)\n integer ( kind = 4 ), save :: icall = 0\n integer ( kind = 4 ) ierr\n integer ( kind = 4 ) k\n integer ( kind = 4 ), save :: kml = 6\n integer ( kind = 4 ), save :: kmx = 5000\n integer ( kind = 4 ) l\n integer ( kind = 4 ) lmn\n integer ( kind = 4 ) lmx\n integer ( kind = 4 ) lr(30)\n integer ( kind = 4 ) mxl\n integer ( kind = 4 ) nbits\n integer ( kind = 4 ) nib\n integer ( kind = 4 ), save :: nlmn = 1\n integer ( kind = 4 ) nlmx\n real ( kind = 8 ) result\n real ( kind = 8 ) tol\n real ( kind = 8 ) vl(30)\n real ( kind = 8 ) vr\n \n integer tid\n \n if ( a == b ) then\n err = 0.0D+00\n result = 0.0D+00\n return\n end if\n \n ! OCG: this error trap is no longer relevant. It prevents revursive i\n ! calling, which happens to occur in parallel execution. \n ! if ( icall /= 0 ) then\n ! write ( *, '(a)' ) ' '\n ! write ( *, '(a)' ) 'GAUS8 - Fatal error!'\n ! write ( *, '(a)' ) ' GAUS8 was called recursively.'\n ! stop 1\n ! end if \n \n icall = 1\n !\n ! DIGITS ( X ) = number of base 2 digits in representation of X.\n !\n k = digits ( result )\n \n anib = log10 ( 2.0D+00 ) * real ( k, kind = 8 ) / 0.30102000D+00\n nbits = int ( anib )\n nlmx = min ( 30, ( nbits * 5 ) / 8 )\n result = 0.0D+00\n ierr = 1\n ce = 0.0D+00\n result = 0.0D+00\n lmx = nlmx\n lmn = nlmn\n \n if ( b /= 0.0D+00 ) then\n \n if ( sign ( 1.0D+00, b ) * a <= 0.0D+00 ) then\n go to 10\n end if\n \n c = abs ( 1.0D+00 - a / b )\n if ( 0.1D+00 < c ) then\n go to 10\n end if\n \n if ( c <= 0.0D+00 ) then\n icall = 0\n if ( err < 0.0D+00 ) then\n err = ce\n end if\n return\n end if\n \n anib = 0.5D+00 - log ( c ) / 0.69314718D+00\n nib = int ( anib )\n lmx = min ( nlmx, nbits-nib-7 )\n \n if ( lmx < 1 ) then\n ierr = -1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAUS8 - Warning!'\n write ( *, '(a)' ) ' A and B are too close to carry out integration.'\n icall = 0\n if ( err < 0.0D+00 ) then\n err = ce\n end if\n return\n end if\n \n lmn = min ( lmn, lmx )\n \n end if\n \n 10 continue\n \n tol = max ( abs ( err ), 2.0D+00**(5-nbits)) / 2.0D+00\n if ( err == 0.0D+00 ) then\n tol = sqrt ( epsilon ( 1.0D+00 ) )\n end if\n \n eps = tol\n hh(1) = ( b - a ) / 4.0D+00\n aa(1) = a\n lr(1) = 1\n l = 1\n est = g8 (func, aa(l) + 2.0D+00 * hh(l), 2.0D+00 * hh(l), tid )\n k = 8\n area = abs ( est )\n ef = 0.5D+00\n mxl = 0\n !\n ! Compute refined estimates, estimate the error, etc.\n !\n 20 continue\n \n gl = g8 (func, aa(l) + hh(l), hh(l), tid )\n gr(l) = g8 (func, aa(l) + 3.0D+00 * hh(l), hh(l), tid )\n k = k + 16\n area = area + ( abs ( gl ) + abs ( gr(l) ) - abs ( est ) )\n \n glr = gl + gr(l)\n ee = abs ( est - glr ) * ef\n ae = max ( eps * area, tol * abs ( glr ) )\n \n if ( ee - ae <= 0.0D+00 ) then\n go to 40\n else\n go to 50\n end if\n \n 30 continue\n \n mxl = 1\n \n 40 continue\n \n ce = ce + ( est - glr )\n \n if ( lr(l) <= 0 ) then\n go to 60\n else\n go to 80\n end if\n !\n ! Consider the left half of this level\n !\n 50 continue\n \n if ( kmx < k ) then\n lmx = kml\n end if\n \n if ( lmx <= l ) then\n go to 30\n end if\n \n l = l + 1\n eps = eps * 0.5D+00\n ef = ef / sqrt ( 2.0D+00 )\n hh(l) = hh(l-1) * 0.5D+00\n lr(l) = -1\n aa(l) = aa(l-1)\n est = gl\n go to 20\n !\n ! Proceed to right half at this level\n !\n 60 continue\n \n vl(l) = glr\n \n 70 continue\n \n est = gr(l-1)\n lr(l) = 1\n aa(l) = aa(l) + 4.0D+00 * hh(l)\n go to 20\n !\n ! Return one level\n !\n 80 continue\n \n vr = glr\n \n 90 continue\n \n if ( l <= 1 ) then\n go to 120\n end if\n \n l = l - 1\n eps = eps * 2.0D+00\n ef = ef * sqrt ( 2.0D+00 )\n \n if ( lr(l) <= 0 ) then\n vl(l) = vl(l+1) + vr\n go to 70\n else\n vr = vl(l+1) + vr\n go to 90\n end if\n !\n ! Exit\n !\n 120 continue\n \n result = vr\n \n if ( mxl == 0 .or. abs ( ce ) <= 2.0D+00 * tol * area ) then \n icall = 0 \n if ( err < 0.0D+00 ) then\n err = ce\n end if\n return\n end if\n \n ierr = 2\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAUS8 - Warning!'\n write ( *, '(a)' ) ' RESULT is probably insufficiently accurate.'\n icall = 0\n \n if ( err < 0.0D+00 ) then\n err = ce\n end if\n \n return\n end subroutine gaus8_threadsafe\n\n!.............................................Boole's rule\n subroutine boole(N,arr,dx,ans)\n!INPUT: \n! N: DIMENSION OF FUNCTION ARRAY\n! arr: ARRAY OF FUNCTION VALUES TO BE INTEGRATED\n! dx: STEP SIZE OF FUNCTION VALUES\n!OUTPUT:\n! ans: DEFINITE INTEGRAL OF FUNCTION ARRAY FROM BOOLES RULE\n!CALLS: \n! NONE \n! \n implicit none \n integer N, i, m\n real(kind=8) arr(N),ans\n integer x0\n real(kind=8) dboole, boole_out,dx\n \n m = N/4\n boole_out = 0 \n \n do i = 1, m-1, 1 \n x0 = 4*i \n dboole = ( 7d0*arr(x0+4) &\n + 32d0*arr(x0+3) &\n + 12d0*arr(x0+2) &\n + 32d0*arr(x0+1) &\n + 7d0*arr(x0) ) \n boole_out = boole_out + dboole\n enddo \n \n ans=dx*(2d0/45d0)*boole_out\n \n end subroutine \n\nend module quadrature \n", "meta": {"hexsha": "91baf77d08e82dd0b6877999a69a05d2ae31bc18", "size": 13146, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quadrature.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/quadrature.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/quadrature.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": 28.6405228758, "max_line_length": 90, "alphanum_fraction": 0.4669861555, "num_tokens": 4229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8933094103149355, "lm_q1q2_score": 0.8427012670929532}} {"text": "program tarefaa\n implicit real*8 (a-h,o-z)\n\n dimension h(14)\n\n ! Funções exatas\n f(x) = sinh(2*x)*sin(x/4)\n df(x) = 2*cosh(2*x)*sin(x/4) + cos(x/4)*sinh(2*x)/4\n d2f(x) = cos(x/4)*cosh(2*x) + 63*sin(x/4)*sinh(2*x)/16\n d3f(x) = 61*cosh(2*x)*sin(x/4)/8 + 191*cos(x/4)*sinh(2*x)/64 \n\n ! Funções aproximaximadas\n dfrente2p(x, h_i) = ( f(x+h_i) - f(x) ) / h_i\n dtras2p(x, h_i) = ( f(x) - f(x-h_i) ) / h_i\n dsimetrica3p(x, h_i) = ( f(x+h_i) - f(x-h_i) ) / ( 2*h_i )\n dsimetrica5p(x, h_i) = ( f(x-2*h_i) -8*f(x-h_i) +8*f(x+h_i) -f(x+2*h_i) ) / ( 12*h_i )\n d2simetrica5p(x, h_i) = ( -f(x-2*h_i) +16*f(x-h_i) -30*f(x) +16*f(x+h_i) -f(x+2*h_i) ) / ( 12*h_i**2 )\n d3antisimetrica5p(x, h_i) = ( -f(x-2*h_i) +2*f(x-h_i) -2*f(x+h_i) +f(x+2*h_i) ) / ( 2*h_i**3 )\n\n ! vetor com os valor de h\n h = (/0.5, 0.2, 0.1, 0.05, 0.01, 0.005, 0.001, 0.0005, 0.0001, 0.00005, 0.00001, 0.000001, 0.0000001, 0.00000001/)\n\n ! Arquivo de saida\n open(10, file='saida-a-10407962')\n\n ! x para calcular a derivada\n x = 1d0\n\n ! valor de cada derivada analitica\n df_x = df(x)\n d2f_x = d2f(x)\n d3f_x = d3f(x)\n\n ! loop para alterar o valor de h\n do i = 1, 14\n\n ! desvio de cada método\n erro1 = abs(dfrente2p(x, h(i)) - df_x)\n erro2 = abs(dtras2p(x, h(i)) - df_x)\n erro3 = abs(dsimetrica3p(x, h(i)) - df_X)\n erro4 = abs(dsimetrica5p(x, h(i)) - df_x)\n erro5 = abs(d2simetrica5p(x, h(i)) - d2f_x)\n erro6 = abs(d3antisimetrica5p(x, h(i)) - d3f_x)\n \n ! escreve no arquivo de saida\n write(10,*) h(i), erro1, erro2, erro3, erro4, erro5, erro6\n end do\n\n ! escreve na tela os valores exatos\n write(*,'(A,F0.11)') 'df/dx: ', df_x\n write(*,'(A,F0.11)') 'd^2f/dx^2: ', d2f_x\n write(*,'(A,F0.11)') 'd^3f/dx^3: ', d3f_x\n\nend program tarefaa\n", "meta": {"hexsha": "d3af917ab0b69be940f683d6140f1da18aee19b9", "size": 1851, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-3/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-3/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-3/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": 33.6545454545, "max_line_length": 118, "alphanum_fraction": 0.5337655321, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341975270266, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.8426006013854832}} {"text": "PROGRAM decay_chain\n\n! The following line below may be used to compile this program:\n! gfortran -o decay_chain decay_chain.f -ffree-form\n\nimplicit none\n\ninteger, parameter :: max_size = 2000\ninteger, parameter :: output = 7\ninteger :: i\nreal :: hl_1,hl_2\nreal :: lambda_1,lambda_2\nreal :: N_0\nreal :: time(max_size)\nreal :: N_1_pop(max_size)\nreal :: N_2_pop(max_size)\nreal :: N_3_pop(max_size)\nreal, dimension(max_size,4) :: results\n\n!Prompts the user for the half lives of parent and daughter and then reads them in\nwrite (*,*) 'Enter half lives of parent and daughter nuclei (in days): '\nread (*,*) hl_1, hl_2\n\n!Prints back out user specified info for reference\nwrite (*,*) 'The half lives are: ', hl_1, ' days and ', hl_2, ' days'\n\n!Initializes initial population of parent nuclide\nN_0 = 1E6\n!Calulates the lambdas of the parent and daughter in inverse seconds\nlambda_1 = log(2.)/(hl_1*24.*60.*60.)\nlambda_2 = log(2.)/(hl_2*24.*60.*60.)\n\n!Creates time array of 3600 second (1 hour) increments\ndo i = 1, max_size\n\ttime(i) = (i-1)*3600.\nend do\n!Creates array of parent population using expression from README.md file\ndo i = 1, max_size\n\tN_1_pop(i) = N_0 * exp(-1.*lambda_1*time(i))\nend do\n!Creates array of daughter population using expression from README.md file\ndo i = 1, max_size\n\tN_2_pop(i) = ((lambda_1*N_0)/(lambda_2 - lambda_1)) * (exp(-1.*lambda_1*time(i)) - exp(-1.*lambda_2*time(i)))\nend do\n!Creates array of granddaughter population using expression from README.md file\ndo i = 1, max_size\n\tN_3_pop(i) = (N_0/(lambda_2 - lambda_1)) * ((lambda_2*(1. - exp(-1.*lambda_1*time(i)))) &\n\t-(lambda_1 *(1. - exp(-1.*lambda_2*time(i)))))\nend do\n\n!Fills each column of the results array with time and populations\nresults(:,1) = time(:)\nresults(:,2) = N_1_pop(:)\nresults(:,3) = N_2_pop(:)\nresults(:,4) = N_3_pop(:)\n\n!Opening a CSV file for preparation of outputting the numbers from results array\nopen(unit=output,file='OUTPUT.csv')\n!Writes out the first line of the CSV file which will just be the lables for the columns\nwrite(output, '(a12,\",\",a17,\",\",a19,\",\",a24)') 'Time_(hours)', 'Parent_Population', 'Daughter_Population', &\n 'Granddaughter_Population'\n!Iterates through the results array and writes out each row\ndo i = 1, max_size\n write(output, '(f0.0,\",\",f0.4,\",\",f0.4,\",\",f0.4)') results(i,1)/3600., results(i,2), results(i,3), results(i,4)\nend do\n\n!Closes the CSV file\nclose (output)\n\n!Ends the program\nEND PROGRAM decay_chain", "meta": {"hexsha": "5f8f6f55b80366a309fbf19292359b7f93b59345", "size": 2444, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "decay_chain.f", "max_stars_repo_name": "rlopezle/decay_demo", "max_stars_repo_head_hexsha": "ad82978269689916c308a8f7b74bd9ff6228859b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "decay_chain.f", "max_issues_repo_name": "rlopezle/decay_demo", "max_issues_repo_head_hexsha": "ad82978269689916c308a8f7b74bd9ff6228859b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "decay_chain.f", "max_forks_repo_name": "rlopezle/decay_demo", "max_forks_repo_head_hexsha": "ad82978269689916c308a8f7b74bd9ff6228859b", "max_forks_repo_licenses": ["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.4225352113, "max_line_length": 115, "alphanum_fraction": 0.7074468085, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8947894632969137, "lm_q1q2_score": 0.8425822228206142}} {"text": "RECURSIVE SUBROUTINE factorial(n, result)\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: n\nINTEGER, INTENT(OUT) :: result\nINTEGER :: temp\n\nIF (n >= 1) THEN\n CALL factorial(n-1, temp)\n result = n * temp\nELSE\n result = 1\nEND IF\nEND SUBROUTINE factorial\n\nRECURSIVE FUNCTION fact(n) RESULT(answer)\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: n\nINTEGER :: answer\nIF (n >= 1) THEN\n answer = n * fact(n-1)\nELSE\n answer = 1\nEND IF\nEND FUNCTION fact\n\nPROGRAM test_factorial\nIMPLICIT NONE\nINTEGER :: i, facto\nINTEGER :: fact\nWRITE(*, *) \"Enter an integer to calculate its factorial:\"\nREAD(*, *) i\nCALL factorial(i, facto)\nWRITE(*, '(I0,A,I0)') i, \"! = \", facto\nWRITE(*, '(I0,A,I0)') i, \"! = \", fact(i)\nEND PROGRAM test_factorial\n", "meta": {"hexsha": "258a894ef75b707510fafa2a3593c478dbdc909c", "size": 707, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap13/test_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/chap13/test_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/chap13/test_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": 19.6388888889, "max_line_length": 58, "alphanum_fraction": 0.676096181, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338101862454, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.842098793638864}} {"text": " MODULE RDistributions\n! Inspired from: http://www.johndcook.com/julia_rng.html\n! Original author in julia : John D Cook\n! coded : Sukhbinder in fortran\n! Date : 28th Feb 2012\n!\n\n!\n! Non uniform random Number Generators in Fortran\n!\n DOUBLE PRECISION, PARAMETER :: PI=3.141592653589793238462\n CONTAINS\n\n FUNCTION rand_uniform(a,b) RESULT(c)\n DOUBLE PRECISION :: a,b,c,temp\n CALL RANDOM_NUMBER(temp)\n c= a+temp*(b-a)\n END FUNCTION\n\n!\n! Random Sample from normal (Gaussian) distribution\n!\n FUNCTION rand_normal(mean,stdev) RESULT(c)\n DOUBLE PRECISION :: mean,stdev,c,temp(2)\n\n IF(stdev <= 0.0d0) THEN\n\n WRITE(*,*) \"Standard Deviation must be +ve\"\n ELSE\n CALL RANDOM_NUMBER(temp)\n r=(-2.0d0*log(temp(1)))**0.5\n theta = 2.0d0*PI*temp(2)\n c= mean+stdev*r*sin(theta)\n END IF\n END FUNCTION\n\n!\n! Random smaple from an exponential distribution\n!\n FUNCTION rand_exponential(mean) RESULT(c)\n DOUBLE PRECISION :: mean,c,temp\n IF (mean <= 0.0d0) THEN\n\n WRITE(*,*) \"mean must be positive\"\n ELSE\n CALL RANDOM_NUMBER(temp)\n c=-mean*log(temp)\n END IF\n END FUNCTION\n\n!\n! Return a random sample from a gamma distribution\n!\n RECURSIVE FUNCTION rand_gamma(shape, SCALE) RESULT(ans)\n DOUBLE PRECISION SHAPE,scale,u,w,d,c,x,xsq,g\n IF (shape <= 0.0d0) THEN\n\n WRITE(*,*) \"Shape PARAMETER must be positive\"\n END IF\n IF (scale <= 0.0d0) THEN\n\n WRITE(*,*) \"Scale PARAMETER must be positive\"\n END IF\n!\n! ## Implementation based on \"A Simple Method for Generating Gamma Variables\"\n! ## by George Marsaglia and Wai Wan Tsang.\n! ## ACM Transactions on Mathematical Software\n\n! ## Vol 26, No 3, September 2000, pages 363-372.\n!\n IF (shape >= 1.0d0) THEN\n d = SHAPE - 1.0d0/3.0d0\n c = 1.0d0/(9.0d0*d)**0.5\n DO while (.true.)\n x = rand_normal(0.0d0, 1.0d0)\n v = 1.0 + c*x\n DO while (v <= 0.0d0)\n x = rand_normal(0.0d0, 1.0d0)\n v = 1.0d0 + c*x\n END DO\n\n v = v*v*v\n CALL RANDOM_NUMBER(u)\n xsq = x*x\n IF ((u < 1.0d0 -.0331d0*xsq*xsq) .OR. &\n (log(u) < 0.5d0*xsq + d*(1.0d0 - v + log(v))) )then\n ans=scale*d*v\n RETURN\n END IF\n\n END DO\n ELSE\n g = rand_gamma(shape+1.0d0, 1.0d0)\n CALL RANDOM_NUMBER(w)\n ans=scale*g*(w)**(1.0d0/shape)\n RETURN\n END IF\n\n END FUNCTION\n!\n! ## return a random sample from a chi square distribution\n! ## with the specified degrees of freedom\n!\n FUNCTION rand_chi_square(dof) RESULT(ans)\n DOUBLE PRECISION ans,dof\n ans=rand_gamma(0.5d0, 2.0d0*dof)\n END FUNCTION\n\n!\n! ## return a random sample from an inverse gamma random variable\n!\n FUNCTION rand_inverse_gamma(shape, SCALE) RESULT(ans)\n DOUBLE PRECISION SHAPE,scale,ans\n\n! ## If X is gamma(shape, scale) then\n! ## 1/Y is inverse gamma(shape, 1/scale)\n ans= 1.0d0 / rand_gamma(shape, 1.0d0 / SCALE)\n END FUNCTION\n!\n!## return a sample from a Weibull distribution\n!\n\n FUNCTION rand_weibull(shape, SCALE) RESULT(ans)\n DOUBLE PRECISION SHAPE,scale,temp,ans\n IF (shape <= 0.0d0) THEN\n\n WRITE(*,*) \"Shape PARAMETER must be positive\"\n END IF\n IF (scale <= 0.0d0) THEN\n\n WRITE(*,*) \"Scale PARAMETER must be positive\"\n END IF\n CALL RANDOM_NUMBER(temp)\n ans= SCALE * (-log(temp))**(1.0 / SHAPE)\n END FUNCTION\n\n!\n!## return a random sample from a Cauchy distribution\n!\n FUNCTION rand_cauchy(median, SCALE) RESULT(ans)\n DOUBLE PRECISION ans,median,scale,p\n\n IF (scale <= 0.0d0) THEN\n\n WRITE(*,*) \"Scale PARAMETER must be positive\"\n END IF\n CALL RANDOM_NUMBER(p)\n ans = median + SCALE*tan(PI*(p - 0.5))\n END FUNCTION\n\n!\n!## return a random sample from a Student t distribution\n!\n FUNCTION rand_student_t(dof) RESULT(ans)\n DOUBLE PRECISION ans,dof,y1,y2\n IF (dof <= 0.d0) THEN\n\n WRITE(*,*) \"Degrees of freedom must be positive\"\n END IF\n!\n! ## See Seminumerical Algorithms by Knuth\n y1 = rand_normal(0.0d0, 1.0d0)\n y2 = rand_chi_square(dof)\n ans= y1 / (y2 / DOf)**0.50d0\n!\n\n END FUNCTION\n\n!\n!## return a random sample from a Laplace distribution\n!## The Laplace distribution is also known as the double exponential distribution.\n!\n FUNCTION rand_laplace(mean, SCALE) RESULT(ans)\n DOUBLE PRECISION ans,mean,scale,u\n IF (scale <= 0.0d0) THEN\n\n WRITE(*,*) \"Scale PARAMETER must be positive\"\n END IF\n CALL RANDOM_NUMBER(u)\n IF (u < 0.5d0) THEN\n\n ans = mean + SCALE*log(2.0*u)\n ELSE\n ans = mean - SCALE*log(2*(1-u))\n END IF\n\n END FUNCTION\n\n!\n! ## return a random sample from a log-normal distribution\n!\n FUNCTION rand_log_normal(mu, sigma) RESULT(ans)\n DOUBLE PRECISION ans,mu,sigma\n ans= EXP(rand_normal(mu, sigma))\n END FUNCTION\n\n!\n! ## return a random sample from a beta distribution\n!\n FUNCTION rand_beta(a, b) RESULT(ans)\n DOUBLE PRECISION a,b,ans,u,v\n IF ((a <= 0.0d0) .OR. (b <= 0.0d0)) THEN\n\n WRITE(*,*) \"Beta PARAMETERs must be positive\"\n END IF\n\n! ## There are more efficient methods for generating beta samples.\n! ## However such methods are a little more efficient and much more complicated.\n! ## For an explanation of why the following method works, see\n! ## http://www.johndcook.com/distribution_chart.html#gamma_beta\n\n u = rand_gamma(a, 1.0d0)\n v = rand_gamma(b, 1.0d0)\n ans = u / (u + v)\n END FUNCTION\n\n\n\nEND MODULE\n", "meta": {"hexsha": "d0647c77fb79153cb14cb875677255d60c175093", "size": 5726, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "original_code/RDistributions.f90", "max_stars_repo_name": "rkganeri/AM-DEM", "max_stars_repo_head_hexsha": "cf608422ad81a7cdf9863b6296205246f51195de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-09T05:23:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T15:02:29.000Z", "max_issues_repo_path": "original_code/RDistributions.f90", "max_issues_repo_name": "rkganeri/AM-DEM", "max_issues_repo_head_hexsha": "cf608422ad81a7cdf9863b6296205246f51195de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "original_code/RDistributions.f90", "max_forks_repo_name": "rkganeri/AM-DEM", "max_forks_repo_head_hexsha": "cf608422ad81a7cdf9863b6296205246f51195de", "max_forks_repo_licenses": ["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.0272727273, "max_line_length": 82, "alphanum_fraction": 0.6019909186, "num_tokens": 1690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8887587920192298, "lm_q1q2_score": 0.8412961171534108}} {"text": "module SpherHarm\n !! Functions related to spherical harmonics\n implicit none\ncontains\n \ncomplex(8) function SpherHarmSpecial(l,m,un)\n !! Ylm as a function of position vector\n integer,intent(in) :: l, m\n real(8),intent(in) :: un(3)\n real(8), parameter :: PI=3.14159265358979D0\n integer :: i,fact,mm\n real(8) :: phi\n mm=abs(m)\n \n fact=1\n do i=l+mm,l-mm+1,-1\n fact=fact*i\n end do\n \n phi=atan2(un(2),un(1))\n\n SpherHarmSpecial=sqrt((2*l+1)/(4*fact*PI))*plgndr(l,mm,un(3))*&\n cmplx(cos(m*phi),sin(m*phi), 8)\nend function SpherHarmSpecial\n\n\nreal(8) function SpherHarmTrunc(l,m,costheta)\n !! Ylm(θ,ϕ) without the exp(i m ϕ) factor \n integer,intent(in) :: l,m\n real(8),intent(in) :: costheta ! cos(θ)\n real(8), parameter :: PI=3.14159265358979D0\n integer :: i,fact,mm\n mm=abs(m)\n \n fact=1\n do i=l+mm,l-mm+1,-1\n fact=fact*i\n end do\n\n SpherHarmTrunc=sqrt((2*l+1)/(4*fact*PI))*plgndr(l,mm,costheta)\nend function SpherHarmTrunc\n\nfunction plgndr(l,m,x)\n !! Computes the associated renormalized Legendre polynomial Pm\n !! l (x). m and l must statisfy 0<=m<=l and x must be in [-1,1].\n !! Legendre polynomial.\n integer, intent(in) :: l,m\n real(8), intent(in) :: x\n real(8) :: plgndr \n integer :: ll\n real(8) :: fact,pll,pmm,pmmp1,somx2\n pll=0.d0\n pmm=1.0 !Compute Pmm\n if (m > 0) then\n somx2=sqrt((1.0D0-x)*(1.0D0+x))\n fact=1.\n do ll=1,m\n pmm=-pmm*fact*somx2\n fact=fact+2.\n enddo\n endif\n \n if (l == m) then\n plgndr=pmm\n else\n pmmp1=x*(2*m+1)*pmm !Compute Pmm+1.\n if (l == m+1) then\n plgndr=pmmp1\n else !Compute Pml , l > m+ 1.\n do ll=m+2,l\n pll=(x*(2*ll-1)*pmmp1-(ll+m-1)*pmm)/(ll-m)\n pmm=pmmp1\n pmmp1=pll\n end do\n plgndr=pll\n end if\n end if\nend function plgndr\n\nend module\n", "meta": {"hexsha": "8912d8aeabad16f8f779e086525d6ee6e95f69ce", "size": 1825, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analysis/spherharm.f90", "max_stars_repo_name": "guibar64/polcolmc", "max_stars_repo_head_hexsha": "59badf4f3f59deb789a8b1906f491c4463842801", "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": "src/analysis/spherharm.f90", "max_issues_repo_name": "guibar64/polcolmc", "max_issues_repo_head_hexsha": "59badf4f3f59deb789a8b1906f491c4463842801", "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": "src/analysis/spherharm.f90", "max_forks_repo_name": "guibar64/polcolmc", "max_forks_repo_head_hexsha": "59badf4f3f59deb789a8b1906f491c4463842801", "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": 22.5308641975, "max_line_length": 66, "alphanum_fraction": 0.5989041096, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8887587905460026, "lm_q1q2_score": 0.8412961104030223}} {"text": "program composite_trapezoidal\n ! Author : Anantha Rao (reg no: 20181044)\n ! Program to evaluate the integral I = Int_a^b f(x)\n implicit none\n real*8,external::func\n ! An external function f in double precision\n\n real*8::a,b,h,trapezoidal_integral\n ! a : Lower limit of the integral\n ! b : Upper limit of the integral\n ! h : bin size\n ! trapezoidal_integral : Value of the integral using trapezoidal technique\n\n integer::n,i\n ! n : number of bins \n ! i : counter\n \n n = 1000\n a = 0\n b = 1\n print 10, n\n 10 format(\"Welcome to this program. &\n & This program does integration on I= Int_0^1 4.0/(1+x^2) using trapezoidal rule with n=\",i5,\" bins\" )\n\n h=(b-a)/real(n) ! size of each bin\n trapezoidal_integral=(h/2)*(func(a)+func(b))\n\n do i=1,n-1\n trapezoidal_integral=trapezoidal_integral+h*func(a+i*h)\n end do\n print *, \"The integrated value using trapezoidal rule is:\",trapezoidal_integral\n !5 format(\"The integrated value using trapezoidal rule is:\",\nend program composite_trapezoidal\n\nreal*8 function func(x)\n implicit none\n real*8::x\n func=4.0d0/(1.0d0+x*x)\n ! func=SIN(x)\nend function\n", "meta": {"hexsha": "3eaaf6d01657601387751ee260c8f79d65bc2d5a", "size": 1189, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn01_solns/Assgn01_A_1_sourcecode.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/assgn01_solns/Assgn01_A_1_sourcecode.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/assgn01_solns/Assgn01_A_1_sourcecode.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.0, "max_line_length": 111, "alphanum_fraction": 0.6526492851, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551958, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.8412070635399318}} {"text": "! Objetivo: Calcular a probabilidade de um caminhante, apos N passos,\n! parar em determinada posicao.\n\nPROGRAM caminhadas_aleatorias\n\n USE nrtype\n USE ran_state, ONLY: ran_seed\n USE nr, ONLY: ran0 \n \n IMPLICIT none\n INTEGER :: iseed = 1234\n INTEGER, PARAMETER :: passos_total = 20, total_caminhantes = 100000\n INTEGER :: passo, caminhante_n, posicao\n INTEGER, PARAMETER :: dados_caminhada_aleatoria = 7\n! Quantidade_posfinais eh a quantidade de caminhantes que terminaram em\n! determinadas posicoes\n INTEGER, DIMENSION (-passos_total:passos_total) :: quantidade_posfinais = 0\n REAL :: aleatorio\n REAL, PARAMETER :: total_caminhantes_real = REAL(total_caminhantes)\n REAL, DIMENSION(-passos_total:passos_total) :: probabilidade\n! Iniciar semente\n CALL RAN_SEED (SEQUENCE = iseed)\n DO caminhante_n = 1, total_caminhantes\n posicao = 0\n DO passo = 1, passos_total\n! Chamar numero aleatorio uniformemente distribuido entre 0. e 1.\n! excluindo os extremos\n CALL ran0(aleatorio)\n! A subrotina retorna um numero aleatorio uniformemente distribuido entre 0. e\n! 1. (excluindo os extremos). Para termos chances iguais de movimentacao (direita\n! e esquerda) assumimos que para aleatorio menor que 0.5 (passo para esquerda)\n! para aleatorio maior que 0.5 (passo para direita) e para 0.5 (nao anda).\n IF(aleatorio < 0.5)THEN\n posicao = posicao-1\n ELSE\n IF(aleatorio > 0.5) THEN\n posicao = posicao+1\n END IF\n END IF\n END DO\n!Contabilizar a quantidade de caminhadas finalizadas em cada posicao\n quantidade_posfinais(posicao) = quantidade_posfinais(posicao) + 1\n END DO\n! Calcular a probabilidade de um caminhante parar em cada posicao\n probabilidade = quantidade_posfinais/total_caminhantes_real\n \n OPEN(dados_caminhada_aleatoria, FILE=\"dados_caminhada_aleatoria.dat\")\n! Escrever a posicao e a probabilidade (excluindo os casos em que a\n! probabilidade eh zero)\n DO posicao = -passos_total, passos_total, 2\n WRITE(dados_caminhada_aleatoria, *) posicao, probabilidade(posicao)\n END DO\n CLOSE(dados_caminhada_aleatoria)\n \nEND PROGRAM caminhadas_aleatorias", "meta": {"hexsha": "0e05b6139a88a5b4ec91e452f60bdcba178628ff", "size": 2259, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Caminhadas_Aleatorias/caminhada_aleatoria.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": "Caminhadas_Aleatorias/caminhada_aleatoria.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": "Caminhadas_Aleatorias/caminhada_aleatoria.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": 41.0727272727, "max_line_length": 81, "alphanum_fraction": 0.7087206729, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361158630024, "lm_q2_score": 0.8757869884059267, "lm_q1q2_score": 0.8410718068986152}} {"text": "module smooth_step\n\n implicit none\n\n public :: smoothstep\n\ncontains\n\n pure function smoothstep (x,N,minV,maxV)\n\n implicit none\n\n real :: smoothstep\n real, intent (in) :: x\n integer, intent (in) :: N \n real, optional, intent (in) :: minV\n real, optional, intent (in) :: maxV\n real :: minVl \n real :: maxVl\n real :: dV\n\n minVl = 0\n maxVl = 1\n\n if(present(minV)) minVl = minV\n if(present(maxV)) maxVl = maxV\n\n dV = maxVl - minVl\n\n if(x .le. 0) then\n smoothstep = minVl\n return\n endif\n if(x .ge. 1) then\n smoothstep = maxVl\n return\n endif\n\n select case (N)\n case(0)\n smoothstep = minVl + dV*smoothstep0(x)\n case(1)\n smoothstep = minVl + dV*smoothstep1(x)\n case(2)\n smoothstep = minVl + dV*smoothstep2(x)\n case default\n smoothstep = minVl + dV*smoothstepN(x,N)\n end select \n end function smoothstep\n\n pure function smoothstep0 (x)\n implicit none\n real :: smoothstep0\n real, intent (in) :: x\n smoothstep0 = x\n end function smoothstep0\n\n pure function smoothstep1 (x)\n implicit none\n real :: smoothstep1\n real, intent (in) :: x\n smoothstep1 = x*x*(3-2*x)\n end function smoothstep1\n\n pure function smoothstep2 (x)\n implicit none\n real :: smoothstep2\n real, intent (in) :: x\n smoothstep2 = x*x*x*(x*(x*6-15)+10)\n end function smoothstep2\n\n pure function smoothstepN (x,N)\n implicit none\n real :: smoothstepN\n real :: sumV\n real :: xp\n real, intent (in) :: x\n integer, intent (in) :: N\n integer :: i\n\n if(N < 0) then\n smoothstepN = 0.5*sin(3.14159265358979*(x-0.5))+0.5\n return\n endif\n\n xp = x\n if(x > 0.5) xp = 1.0-x\n sumV = 0\n do i = N, 0, -1\n sumV = xp*sumV + &\n pascalTriangle(-N-1,i) * &\n pascalTriangle(2*N + 1, N-i)\n end do\n sumV = xp**(N+1)*sumV\n smoothstepN = sumV\n if(x > 0.5) smoothstepN = 1-sumV\n end function smoothstepN\n\n pure function pascalTriangle (a,b)\n implicit none\n integer :: pascalTriangle\n integer, intent (in) :: a,b\n integer i\n pascalTriangle = 1\n do i = 0, b-1\n pascalTriangle = pascalTriangle*(a-i)/(i+1)\n end do\n end function pascalTriangle\n\nend module smooth_step\n", "meta": {"hexsha": "02bf7c742a3e1b116b0a1a306f81f17264751976", "size": 2280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/smooth_step.f90", "max_stars_repo_name": "SStroteich/stella-1", "max_stars_repo_head_hexsha": "104556a07b9736e7c28e6f1bf2f799384732f38b", "max_stars_repo_licenses": ["MIT"], "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/utils/smooth_step.f90", "max_issues_repo_name": "SStroteich/stella-1", "max_issues_repo_head_hexsha": "104556a07b9736e7c28e6f1bf2f799384732f38b", "max_issues_repo_licenses": ["MIT"], "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/smooth_step.f90", "max_forks_repo_name": "SStroteich/stella-1", "max_forks_repo_head_hexsha": "104556a07b9736e7c28e6f1bf2f799384732f38b", "max_forks_repo_licenses": ["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.5405405405, "max_line_length": 57, "alphanum_fraction": 0.5855263158, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.96036116089903, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8410718011020056}} {"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_differentiate\nCONTAINS\n REAL FUNCTION difcub(x,f,xi)\n ! **********************************************************\n ! differentiate the function f, given at the\n ! points x0,x1,x2,x3 at the point xi by lagrange\n ! interpolation for polynomial of 3rd order\n ! r.p.\n ! ***********************************************************\n IMPLICIT NONE\n ! .. Scalar Arguments ..\n REAL,INTENT(IN):: xi\n ! ..\n ! .. Array Arguments ..\n REAL,INTENT(IN):: f(0:3),x(0:3)\n ! ..\n difcub = ((xi-x(1))* (xi-x(2))+ (xi-x(1))* (xi-x(3))+&\n (xi-x(2))* (xi-x(3)))*f(0)/ ((x(0)-x(1))* (x(0)-x(2))*&\n (x(0)-x(3))) + ((xi-x(0))* (xi-x(2))+&\n (xi-x(0))* (xi-x(3))+ (xi-x(2))* (xi-x(3)))*f(1)/&\n ((x(1)-x(0))* (x(1)-x(2))* (x(1)-x(3))) +&\n ((xi-x(0))* (xi-x(1))+ (xi-x(0))* (xi-x(3))+&\n (xi-x(1))* (xi-x(3)))*f(2)/ ((x(2)-x(0))* (x(2)-x(1))*&\n (x(2)-x(3))) + ((xi-x(0))* (xi-x(1))+&\n (xi-x(0))* (xi-x(2))+ (xi-x(1))* (xi-x(2)))*f(3)/&\n ((x(3)-x(0))* (x(3)-x(1))* (x(3)-x(2)))\n RETURN\n END FUNCTION difcub\n SUBROUTINE diff3(&\n f,dx,&\n df)\n !********************************************************************\n ! differetiation via 3-points\n !********************************************************************\n\n IMPLICIT NONE\n\n ! .. Scalar Arguments ..\n REAL, INTENT (IN) :: dx\n ! ..\n ! .. Array Arguments ..\n REAL, INTENT (IN) :: f(:)\n REAL, INTENT (OUT) :: df(:)\n ! ..\n ! .. Local Scalars ..\n INTEGER i,jri\n REAL tdx_i\n ! ..\n jri=size(f)\n tdx_i = 1./(2.*dx)\n !\n !---> first point\n df(1) = -tdx_i * (-3.*f(1)+4.*f(2)-f(3))\n !\n !---> central point formula in charge\n DO i = 2,jri - 1\n df(i) = tdx_i * (f(i+1)-f(i-1))\n END DO\n !\n !---> last point\n df(jri) = tdx_i * (3.*f(jri)-4.*f(jri-1)+f(jri-2))\n !\n RETURN\n END SUBROUTINE diff3\n\nEND MODULE m_differentiate\n", "meta": {"hexsha": "de2400ef0d32de067a34566e61efcd9e07137251", "size": 2434, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/differentiate.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/differentiate.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/differentiate.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": 33.3424657534, "max_line_length": 81, "alphanum_fraction": 0.3849630238, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777987970315, "lm_q2_score": 0.8774767970940975, "lm_q1q2_score": 0.8399890568177071}} {"text": "! Counts the number of non-prime factors of a given number n.\n! Works for any n <= 1000000.\n\nmodule npf_module\n implicit none\n\n ! Declarations.\n integer, parameter :: max_n = 1000000\n integer, dimension (0:max_n + 1) :: factors, memo = -1\n\n public :: eratosthenes, npf\n\ncontains\n\n ! Runs the sieve of eratosthenes.\n subroutine eratosthenes ()\n integer :: i, j\n\n ! Initialize each of the factors to itself.\n do i = 0, max_n\n factors(i) = i\n end do\n\n ! Run the sieve.\n do i = 2, 1000\n if (factors(i) == i) then\n do j = i + i, max_n, i\n factors(j) = i\n end do\n end if\n end do\n\n end subroutine eratosthenes\n\n ! Counts the number of non-prime factors of a given number.\n function npf (x) result (cnt)\n integer, intent (in) :: x\n integer :: cnt, pfactors, d, prod, n\n\n cnt = 0\n \n ! Handle trivial cases.\n if (memo(x) /= -1) then\n cnt = memo(x)\n return\n else if (x == 0 .or. x == 1) then\n memo(x) = cnt\n return\n end if\n\n ! Solve general case.\n n = x\n pfactors = 0\n prod = 1\n\n do while (n > 1)\n d = factors(n)\n cnt = 0\n\n do while (mod(n, d) == 0)\n n = n / d\n cnt = cnt + 1\n end do\n\n prod = prod * (cnt + 1)\n pfactors = pfactors + 1\n end do\n\n memo(x) = prod - pfactors\n cnt = memo(x)\n end function npf\n\nend module npf_module\n\n! Driver code.\nprogram main\n use npf_module\n implicit none\n\n character(len = 100) :: input\n integer :: n\n\n call eratosthenes()\n\n ! Print information for the user.\n print '(a)', 'For any number of queries, this program gets the number of non-prime factors of a given number x <= 1000000.'\n print '(a)', 'To stop the queries and end the program, input \"exit\".'\n\n do while (input /= 'exit')\n read (*, *) input\n\n if (input /= 'exit') then\n read (input, *) n\n print '(a, i0)', 'The number of non-prime factors is: ', npf(n)\n end if\n end do\n\nend program main", "meta": {"hexsha": "0e998c7e860b3a471ef60300a4dbd1f3926da970", "size": 2258, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nonprimefactors.f90", "max_stars_repo_name": "ngergel/fortran-examples", "max_stars_repo_head_hexsha": "e6698d9b7731d31936e85c941b57f16ea87adf06", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nonprimefactors.f90", "max_issues_repo_name": "ngergel/fortran-examples", "max_issues_repo_head_hexsha": "e6698d9b7731d31936e85c941b57f16ea87adf06", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nonprimefactors.f90", "max_forks_repo_name": "ngergel/fortran-examples", "max_forks_repo_head_hexsha": "e6698d9b7731d31936e85c941b57f16ea87adf06", "max_forks_repo_licenses": ["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.0408163265, "max_line_length": 127, "alphanum_fraction": 0.5035429584, "num_tokens": 628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.88242786954645, "lm_q1q2_score": 0.8399506387531873}} {"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 :: gaussian, gaussian_prime\n public :: relu, relu_prime\n public :: sigmoid, sigmoid_prime\n public :: step, step_prime\n public :: tanhf, tanh_prime\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 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 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 endfunction 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 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 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\nend module mod_activation\n", "meta": {"hexsha": "541272175bba9868401a8e85d927c6808badffcd", "size": 2603, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/mod_activation.f90", "max_stars_repo_name": "jvdp1/neural-fortran", "max_stars_repo_head_hexsha": "ef9efbcb037328caf7cc17d0e393ddb3959c13f3", "max_stars_repo_licenses": ["MIT"], "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/lib/mod_activation.f90", "max_issues_repo_name": "jvdp1/neural-fortran", "max_issues_repo_head_hexsha": "ef9efbcb037328caf7cc17d0e393ddb3959c13f3", "max_issues_repo_licenses": ["MIT"], "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/mod_activation.f90", "max_forks_repo_name": "jvdp1/neural-fortran", "max_forks_repo_head_hexsha": "ef9efbcb037328caf7cc17d0e393ddb3959c13f3", "max_forks_repo_licenses": ["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.7722772277, "max_line_length": 79, "alphanum_fraction": 0.6354206685, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8791467690927438, "lm_q1q2_score": 0.8398657229972115}} {"text": "; Evalutes x +y\n(define (add x y)\n (ifz y x ; if y==0, x+y=x\n (add (inc x) (dec y)))) ; otherwise x+y = (x+1) + (y-1)\n\n; Evalutes x - y\n(define (sub x y)\n (ifz y x ; if y==0, x-y = x\n (ifz x (halt) ; else if x==0, we halt because the result is negative\n (sub (dec x) (dec y))))) ; else x-y = (x-1) - (y-1)\n\n; Evaluates to 0 if x < y, and 1 otherwise\n(define (lt x y)\n (ifz y 1 ; if y==0, x=j\n !\n ! Steps of the Algorithm\n ! 1.- Find the largest absolute element in the row to be used as \n ! 2.- if big == 0.0 you have a singular matrix return with error\n ! 3.- if not singularity save the scalling vv(i) = 1.0/big\n ! 4.- Loop over the betas \n ! 5.- Loop over the betas and look if you have a new max pivote\n ! 6.- Move the max row pivote upwards\n ! 7.- Use TINY number if division by zero arises \n ! 8.- Divide by pivote element\n\n\n ! In parameters\n integer, intent(in) :: n\n real, intent(inout) :: A(n,n)\n ! Out Parameters\n integer, intent(out) :: indx(n)\n ! Parameters\n real, parameter :: TINY = 1.0E-30\n\n ! Internal variables\n ! Indexing\n integer :: i\n integer :: j\n integer :: k\n ! max index pivot\n integer :: imax\n ! Internal variables for the Crout's method\n real :: big\n real :: dum\n real :: sum\n real :: temp\n real, dimension (n) :: vv\n\n ! Chose the variable for permutation\n do i = 1, n\n big = 0.0\n do j = 1, n\n temp = abs(A(i,j)) \n if (temp > big) then\n big = temp\n end if \n end do\n if (big == 0.0) then\n print*,\"Singular matrix in routine ludcmp\"\n return\n end if\n ! Save the Scaling\n vv(i) = 1.0/big\n end do\n ! This is the loop over columns of Crout’s method.\n ! For the upper triangular part of A(i,j)=beta_ij with i<=j\n do j = 1, n\n do i = 1, j-1\n sum = A(i,j)\n do k = 1, i-1\n sum = sum - A(i,k)*A(k,j)\n end do \n A(i,j) = sum\n end do\n ! Start the search for the largest pivot element\n big = 0.0\n imax = j\n do i = j, n\n sum = A(i,j)\n do k = 1, j-1\n sum = sum - A(i,k)*A(k,j)\n end do\n A(i,j) = sum\n dum = vv(i)*abs(sum)\n if (dum >= big) then\n big = dum\n imax = i\n end if \n end do \n ! Interchage Rows a classic to mantain stability getting \n ! The Largest absolute value in the choosen pivot\n if (j /= imax) then\n do k = 1, n \n dum = A(imax,k)\n A(imax,k) = A(j,k)\n A(j,k) = dum\n end do\n ! Interchange the scale factor\n vv(imax) = vv(j)\n end if\n indx(j) = imax\n ! Solving some issues with zero pivots\n !\n if (A(j,j) == 0) then\n A(j,j) = TINY\n end if\n ! Divide by the pivot element.\n if (j /= n) then\n dum = 1.0/A(j,j)\n do i = j+1, n\n A(i,j) = A(i,j)*dum ! Division \n end do\n end if\n end do \n\n end subroutine ludcmp_square\n\nend module LUDecomposition\n", "meta": {"hexsha": "f8b5044f6db9f35984bb8bf4a0c311ad538c0529", "size": 3126, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mathtools/LinearAlgebra/LUDecomposition/LU.f90", "max_stars_repo_name": "kajuna0amendez/Cython_Machine_Learning_Models", "max_stars_repo_head_hexsha": "8b7d502bae07487ae0fdbced796e0fa50082e681", "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": "mathtools/LinearAlgebra/LUDecomposition/LU.f90", "max_issues_repo_name": "kajuna0amendez/Cython_Machine_Learning_Models", "max_issues_repo_head_hexsha": "8b7d502bae07487ae0fdbced796e0fa50082e681", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-02-02T23:02:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-23T20:51:22.000Z", "max_forks_repo_path": "mathtools/LinearAlgebra/LUDecomposition/LU.f90", "max_forks_repo_name": "kajuna0amendez/Machine_Learning_Models", "max_forks_repo_head_hexsha": "8b7d502bae07487ae0fdbced796e0fa50082e681", "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.9482758621, "max_line_length": 72, "alphanum_fraction": 0.4907229687, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.8774767826757123, "lm_q1q2_score": 0.8394243032679434}} {"text": "module statistics\n !! Provides routines for basic statistical methods. \n \n implicit none\n \n public :: factorial, mean, variance, standardDeviation, covariance\n\n public\n\n interface median\n module procedure median_real, median_int\n end interface median\n \ncontains\n\n pure 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\n end function factorial\n\n pure 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, intent(in) :: x(:)\n\n real :: Sx\n integer :: n, i, l, u\n\n mu = 0.0\n Sx = 0.0\n\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\n end function mean\n \n pure integer function median_int(x) result(xm)\n\n integer, intent(in) :: x(:)\n\n xm = ceiling(size(x)/2.0)\n \n end function median_int\n \n pure integer function median_real(x) result (xm)\n\n real, intent(in) :: x(:)\n \n xm = ceiling(size(x)/2.0)\n \n end function median_real\n\n pure 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, 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 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\n end function variance\n\n pure 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, intent(in) :: x(:)\n\n s = sqrt(variance(x))\n\n end function standardDeviation\n\n pure 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, 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 \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\n end function covariance\n\nend module statistics\n\n", "meta": {"hexsha": "13fd20c69c6ffe4ad1ed78bff08e5268e28ba535", "size": 2845, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "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": "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": "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.4863013699, "max_line_length": 101, "alphanum_fraction": 0.5507908612, "num_tokens": 948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.8902942363098472, "lm_q1q2_score": 0.8391083044428206}} {"text": "\t!>@author\n\t!>Paul J. Connolly, The University of Manchester\n\t!>@copyright 2019\n\t!>@brief\n\t!>calculate the inverse of erf\n\t!> This implementation is based on the rational approximation\n !> of percentage points of normal distribution available from\n !> https://www.jstor.org/stable/2347330.\n\t!>@param[in] x: input integer\n\t!>@param[inout] ans: the output\n\tsubroutine erfinv(x,ans) \n\t use, intrinsic :: IEEE_ARITHMETIC\n\t use numerics, only : LN2,A0,A1,A2,A3,A4,A5,A6,A7, &\n\t B0,B1,B2,B3,B4,B5,B6,B7, &\n\t C0,C1,C2,C3,C4,C5,C6,C7, &\n\t D0,D1,D2,D3,D4,D5,D6,D7, &\n\t E0,E1,E2,E3,E4,E5,E6,E7, &\n\t F0,F1,F2,F3,F4,F5,F6,F7\n\t use numerics_type\n implicit none\n real(wp), intent(in) :: x\n real(wp), intent(inout) :: ans\n complex(wp) :: num, den\n real(wp) :: abs_x, r\n \n if((x>1._wp) .or. (x<-1._wp)) then\n ans=IEEE_VALUE(0._wp,IEEE_QUIET_NAN)\n return\n elseif((x==1._wp) ) then\n ans=IEEE_VALUE(0._wp,IEEE_POSITIVE_INF)\n return\n elseif((x==-1._wp) ) then\n ans=IEEE_VALUE(0._wp,IEEE_POSITIVE_INF)\n endif\n \n \n abs_x=abs(x)\n if(abs_x <= 0.85_wp) then\n r = 0.180625_wp - 0.25_wp * x * x\n num = (((((((A7 * r + A6) * r + A5) * r + A4) * r + A3) &\n * r + A2) * r + A1) * r + A0)\n den = (((((((B7 * r + B6) * r + B5) * r + B4) * r + B3) &\n * r + B2) * r + B1) * r + B0)\n ans = x * num / den\n return\n endif\n \n r = sqrt(LN2 - log(1.0_wp - abs_x))\n if (r <= 5.0_wp) then\n r = r - 1.6;\n num = (((((((C7 * r + C6) * r + C5) * r + C4) * r + C3) * &\n r + C2) * r + C1) * r + C0)\n den = (((((((D7 * r + D6) * r + D5) * r + D4) * r + D3) * &\n r + D2) * r + D1) * r + D0)\n else \n r = r - 5.0_wp\n num = (((((((E7 * r + E6) * r + E5) * r + E4) * r + E3) * &\n r + E2) * r + E1) * r + E0)\n den = (((((((F7 * r + F6) * r + F5) * r + F4) * r + F3) * &\n r + F2) * r + F1) * r + F0)\n endif\n if (x < 0._wp) then\n ans= real(-num/den,wp)\n return\n else \n ans = real(num/den,wp)\n return\n endif \n \n end subroutine erfinv\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n", "meta": {"hexsha": "349c4416e0cd1f3f97f721b3f3974af118862d6f", "size": 2554, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "erfinv.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": "erfinv.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": "erfinv.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": 34.5135135135, "max_line_length": 81, "alphanum_fraction": 0.4032889585, "num_tokens": 882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122720843811, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.8389271085842148}} {"text": "!NEWTON RAPHSON METHOD (for finding root of real valued function)\r\n\r\nprogram NewtonRaphson\r\n\r\n implicit none\r\n\r\n real :: x0,x1,e,f,fd\r\n integer :: i !Counting Iterations\r\n\r\n print*,\"Enter the initial guess : \"\r\n read*,x0\r\n print*,\"Enter the value of tolerance : \"\r\n read*,e\r\n\r\n print*,\" n x0 x1 \"\r\n print*,\"---------------------------------------------\"\r\n\r\n i=0 !Initial value\r\n x1=x0-f(x0)/fd(x0)\r\n print*,i,x0,x1\r\n\r\n do while(abs(x1-x0)>e)\r\n x0=x1\r\n x1=x0-f(x0)/fd(x0)\r\n i=i+1 !Increase 1 after each loop\r\n print*,i,x0,x1\n end do\r\n\r\n print*,\"The value of root x after \",i,\" iteration(s) : \",x1\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=x-exp(-x)\nend function\r\n\r\nfunction fd(x)\r\n implicit none\r\n real::fd !Dummy Variable\r\n real::x !Local Variable\r\n fd=1+exp(-x)\nend function\r\n", "meta": {"hexsha": "1822dd60f2409c53ad0c9c22729c91ab993447ad", "size": 984, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "3_Newton_Raphson_Method.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": "3_Newton_Raphson_Method.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": "3_Newton_Raphson_Method.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": 21.3913043478, "max_line_length": 66, "alphanum_fraction": 0.5172764228, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611654370414, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.8377685350375877}} {"text": "program main\n use m_npy\n real :: x(1000)\n real :: step \n integer :: n\n real, allocatable :: P(:,:)\n\n step = 2.0 / (size(x) - 1)\n\n x(1) = -1.0\n do n = 2,size(x)\n x(n) = x(n-1) + step\n enddo \n\n call legendre_poly(10, x, P)\n\n call save_npy(\"leg.npy\", P)\n\ncontains\n subroutine legendre_poly(n_max, x, P)\n implicit none\n integer, intent(in) :: n_max\n real, intent(in) :: x(:)\n real, intent(inout), allocatable :: P(:,:)\n\n integer :: n\n\n if(allocated(P)) then \n if(size(P,1) /= size(x) .or. size(P,2) /= n_max+1) then \n deallocate(P)\n endif \n endif \n \n if(.not. allocated(P)) then\n allocate(P(size(x), 0:n_max), source=0.0)\n endif\n\n if (n_max >= 0) then\n P(:, 0) = 1.0\n endif\n\n if (n_max >= 1) then\n P(:, 1) = x\n endif\n\n do n = 1, n_max - 1\n P(:, n + 1) = ((2*n + 1)*x*P(:, n) - n*P(:, n - 1))/(n + 1.0)\n enddo\n end subroutine legendre_poly\nend program main\n", "meta": {"hexsha": "8c9b379519d30c434711fd0137cbf5a8241fb058", "size": 1057, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "leg.f90", "max_stars_repo_name": "MRedies/fort_leg_poly", "max_stars_repo_head_hexsha": "b223f3bd5e504e88a932f6be075d3f5219b51da6", "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": "leg.f90", "max_issues_repo_name": "MRedies/fort_leg_poly", "max_issues_repo_head_hexsha": "b223f3bd5e504e88a932f6be075d3f5219b51da6", "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": "leg.f90", "max_forks_repo_name": "MRedies/fort_leg_poly", "max_forks_repo_head_hexsha": "b223f3bd5e504e88a932f6be075d3f5219b51da6", "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.7254901961, "max_line_length": 70, "alphanum_fraction": 0.4626300851, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012717045181, "lm_q2_score": 0.8856314798554444, "lm_q1q2_score": 0.8376313799088336}} {"text": "program main\n implicit none\n\n call ball(-9.8, 20.0)\n call ball(-9.7, 20.0)\n call ball(-9.6, 20.0)\n call ball(-9.81, 10.0)\n call ball(-9.81, 20.0)\n call ball(-9.81, 30.0)\n call compute()\nend program main\n\nsubroutine compute\n implicit none\n real :: gravity\n\n write (*,'(A)') 'Please input the gravity:'\n read (*,*) gravity\n call ball(gravity, 20.0)\nend subroutine compute\n\nSUBROUTINE ball(GRAVITY,v)\n!\n! Purpose:\n! To calculate distance traveled by a ball thrown at a specified\n! angle THETA and at a specified velocity VO from a point on the \n! surface of the earth, ignoring the effects of air friction and\n! the earth's curvature.\n!\n! Record of revisions:\n! Date Programmer Description of change\n! ==== ========== =====================\n! 11/14/06 S. J. Chapman Original code\n! 04/12/17 hopeful For homework 6 in chapter6\n!\nIMPLICIT NONE\n\n! Add parameters\nREAL :: GRAVITY\nREAL :: v\n\n! Data dictionary: declare constants\nREAL, PARAMETER :: DEGREES_2_RAD = 0.01745329 ! Deg ==> rad conv.\n!REAL, PARAMETER :: GRAVITY = -9.81 ! Accel. due to gravity (m/s)\n! Data dictionary: declare variable types, definitions, & units\nINTEGER :: max_degrees ! angle at which the max rng occurs (degrees)\nREAL :: max_range ! Maximum range for the ball at vel v0 (meters)\nREAL :: range ! Range of the ball at a particular angle (meters)\nREAL :: radian ! Angle at which the ball was thrown (in radians)\nINTEGER :: theta ! Angle at which the ball was thrown (in degrees)\nREAL :: v0 ! Velocity of the ball (in m/s)\n\n! Initialize variables.\nmax_range = 0\nmax_degrees = 0\n!v0 = 20\nv0 = v\nloop: DO theta = 0, 90\n\n ! Get angle in radians\n radian = real(theta) * DEGREES_2_RAD\n\n ! Calculate range in meters.\n range = (-2. * v0**2 / GRAVITY) * SIN(radian) * COS(radian)\n\n ! Write out the range for this angle.\n WRITE (*,*) 'Theta = ', theta, ' degrees; Range = ', range, ' meters'\n\n ! Compare the range to the previous maximum range. If this\n ! range is larger, save it and the angle at which it occurred.\n IF ( range > max_range ) THEN\n max_range = range\n max_degrees = theta\n END IF\n\nEND DO loop\n ! Skip a line, and then write out the maximum\n! range and the angle at which it occurred.\nWRITE (*,*) ' '\nWRITE (*,*) 'Max range = ', max_range, ' at ', & \n max_degrees, ' degrees'\n\nEND SUBROUTINE ball\n", "meta": {"hexsha": "6979507e8228663ba2812aa9557f9ba9e7b0388c", "size": 2500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter6/6_6/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_6/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_6/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": 29.7619047619, "max_line_length": 76, "alphanum_fraction": 0.6208, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8918110360927155, "lm_q1q2_score": 0.8374326938260218}} {"text": "program Fibonacci\n implicit none\n CHARACTER(100) :: arg\n integer :: input\n\n if (command_argument_count() > 0) then\n call get_command_argument(1, arg)\n read (arg, *) input\n else\n input = 29\n endif\n\n print *, fibLinear(input)\n\ncontains\n\n recursive function fib(n) result(r)\n implicit none\n integer :: n, r\n\n if (n < 2) then\n r = n\n else\n r = fib(n - 1) + fib(n - 2)\n endif\n end function fib\n\n integer function fibLinear(n)\n implicit none\n integer :: n, i, temp, prevFib = 0, fib = 1\n\n do i = 2, n\n temp = prevFib + fib\n prevFib = fib\n fib = temp\n enddo\n fibLinear = fib\n end function fibLinear\n\n integer function fibFormula(n)\n implicit none\n integer :: n\n\n fibFormula = nint(((5 ** 0.5 + 1) / 2) ** n / 5 ** 0.5)\n end function fibFormula\n\n recursive function fibTailAuxiliary(n, prevFib, fib) result(r)\n implicit none\n integer :: n, prevFib, fib, r\n\n if (n == 0) then\n r = prevFib\n else\n r = fibTailAuxiliary(n - 1, fib, prevFib + fib)\n endif\n end function fibTailAuxiliary\n\n integer function fibTailRecursive(n)\n implicit none\n integer :: n\n\n fibTailRecursive = fibTailAuxiliary(n, 0, 1)\n end function fibTailRecursive\n\nend program Fibonacci\n", "meta": {"hexsha": "cbb600b3e39f198765e105386f6529c08c2b1810", "size": 1266, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "language/fortran/fib.f95", "max_stars_repo_name": "A1rPun/nurture", "max_stars_repo_head_hexsha": "d050837444a7ffb6d38be78044e7c1678f92b2b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-30T17:12:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-30T17:12:31.000Z", "max_issues_repo_path": "language/fortran/fib.f95", "max_issues_repo_name": "A1rPun/nurture", "max_issues_repo_head_hexsha": "d050837444a7ffb6d38be78044e7c1678f92b2b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "language/fortran/fib.f95", "max_forks_repo_name": "A1rPun/nurture", "max_forks_repo_head_hexsha": "d050837444a7ffb6d38be78044e7c1678f92b2b0", "max_forks_repo_licenses": ["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.1818181818, "max_line_length": 64, "alphanum_fraction": 0.6192733017, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.9059898254600903, "lm_q1q2_score": 0.836264091360585}} {"text": "program newton\nuse funcs\nimplicit none\n\nreal(kind=8) :: Er, x_old, x_new, true_x\nreal(kind=8) :: TrueError, TrueRelativeError, Tolerance\ninteger :: itermax, i\n\ntrue_x = -3.024185183530358\n\nx_old = -3.0 ! starting value of x\nitermax = 20\n\ni = 1\nEr = 1\nwrite(*,*) \"iteration x |f(x)| Err\"\ndo while (Er > 0.0001)\n ! determine the new x and the error:\n x_new = x_old - f(x_old)/df_dx(x_old)\n Er = dabs((x_new-x_old) / x_old)\n write(*,'(A2,I2,A2,3F12.7)') \" \", i, \" \", x_new, dabs(f(x_new)), Er\n\n ! check if the maximum number of iterations has been exceeded:\n i = i+1 \n if (i > itermax) then\n write(*,*) \"The maximum number of iterations has been exceeded.\"\n exit\n end if\n\n x_old = x_new\nend do\nwrite(*,*)\n\nTrueError = true_x - x_new\nwrite(*,*) \"TrueError:\", TrueError\n\nTrueRelativeError = dabs( (true_x-x_new) / true_x )*100\nwrite(*,*) \"TrueRelativeError:\", TrueRelativeError\n\nTolerance = dabs(f(x_new))\nwrite(*,*) \"Tolerance:\", Tolerance\n\nend program newton\n", "meta": {"hexsha": "24afe4a779cca94791501048ae81e48eea6728fe", "size": 1000, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex1/c-d/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/HW4/ex1/c-d/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/HW4/ex1/c-d/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": 22.7272727273, "max_line_length": 72, "alphanum_fraction": 0.645, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377296574668, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.8361778799494742}} {"text": "real*8 function Wl(l, half, r, d)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the minimum amplitude downward continuation \n!\tfilter of Wieczorek and Phillips 1998 for degree l, where the filter is assumed\n!\tto be equal to 0.5 at degree half.\n!\n!\tCalling Parameters:\n!\t\tl\tspherical harmonic degree\n!\t\thalf \tspherical harmonic degree where the filter is 0.5\n!\t\tr \treference radius for surface gravity field\n!\t\td\tmean radius of downward continuation\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) ::\tl, half\n\treal*8, intent(in) ::\tr, d\n\treal*8 ::\t\tconst\n\t\n\tif (half == 0) then\n\t\n\t\twl=1.0d0\n\t\t\n\telse\n\t\n\t\tconst = ( dble(2*half+1) * (r/d)**half )**2\n\t\tconst = 1.0d0/const\n\t\n\t\twl = 1.0d0 + const * ( dble(2*l+1)*(r/d)**l )**2\n\t\twl = 1.0d0/wl\n\t\t\n\tendif\n\t\nend function Wl\n\t\n\t\nreal*8 function WlCurv(l, half, r, d)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute a minimum curvature downward continuation \n!\tfilter for degree l, where the filter is assumed to be equal to 0.5 at degree half.\n!\n!\tCalling Parameters:\n!\t\tl\tspherical harmonic degree\n!\t\thalf \tspherical harmonic degree where the filter is 0.5\n!\t\tr \treference radius for surface gravity field\n!\t\td\tmean radius of downward continuation\n!\n!\tDependencies:\tNone\n!\n!\tNote: This filter is analogous to (and numerically very similar to) \n!\t\tthe minimum curvature filter in Phipps Morgan and Blackman (1993)\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) ::\tl, half\n\treal*8, intent(in) ::\tr, d\n\treal*8 ::\tconst\n\t\n\tif (half == 0) then\n\t\tWlCurv=1.0d0\n\telse\n\t\tconst = dble(half*half+half) * ( dble(2*half+1) * (r/d)**half )**2\n\t\tconst = 1.0d0/const\n\t\n\t\tWlCurv = 1.0d0 + const * dble(l*l+l) * ( dble(2*l+1)*(r/d)**l )**2\n\t\tWlCurv = 1.0d0/WlCurv\n\tendif\n\t\nend function WlCurv\n\n\t", "meta": {"hexsha": "a7e00d27fe0881256e7ed8eee326e0f857323da8", "size": 2213, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/wl.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/wl.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/wl.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": 26.3452380952, "max_line_length": 85, "alphanum_fraction": 0.5878897424, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491108, "lm_q2_score": 0.8840392771633078, "lm_q1q2_score": 0.8361254698766994}} {"text": "module module_triSolve\n\nimplicit none\ncontains\n\tsubroutine triSolve(a,b,c,d,x,n) \n\t\timplicit none\n\t\tinteger::i\n\t\tinteger,intent(IN) ::n\n\t\treal(8) ::a(n),b(n),c(n),d(n),x(n)\n\t\t! a is the lower diagonal of the tridiagonal matrix\n\t ! b is the main diagonal of the tridiagonal matrix\n\t ! c is the upper diagonal of the tridiagonal matrix\n\t ! d is the right hand side of the equations of the tridiagonal matrix\n\t ! x is the numerical value calculated from the thomas algorithm\n\t ! n is the number of discritizations\n\t \n\n\t\t\n\t\tdo i=2,n\n\t\t\tb(i)=b(i)-((a(i)/b(i-1))*c(i-1))\n\t\t\td(i)=d(i)-((a(i)/b(i-1))*d(i-1))\n\t\tend do\n\t\t\tx(n)=d(n)/b(n)\n\t\tdo i=n-1,1,-1\n\t\t\tx(i)=(d(i)-(c(i)*x(i+1)))/b(i) \n\t\tend do\n\tend subroutine triSolve\n\nend module module_triSolve\n\n!USAGE: USE module_triSolve\n\t!way to define in main program \n\t!a=-1.0d0\n\t!a(1)=0.0d0\t\n\t!b=2.0d0\t\t\t\n\t!c=-1.0d0\n\t!c(n)=0.0d0\n\t!call triSolve(a,b,c,d,u,n)\n", "meta": {"hexsha": "80229d71c49f1652344b364fa305d6bec36e8534", "size": 902, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dev/src/v6/module_triSolve.f90", "max_stars_repo_name": "aakash30jan/Couette-Poiseuille_FlowCode", "max_stars_repo_head_hexsha": "3110d5d818cb8fdfb4959e58d9dcbc48db325122", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-01-05T09:05:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T19:04:14.000Z", "max_issues_repo_path": "dev/src/v7/module_triSolve.f90", "max_issues_repo_name": "aakash30jan/Couette-Poiseuille_FlowCode", "max_issues_repo_head_hexsha": "3110d5d818cb8fdfb4959e58d9dcbc48db325122", "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": "dev/src/v7/module_triSolve.f90", "max_forks_repo_name": "aakash30jan/Couette-Poiseuille_FlowCode", "max_forks_repo_head_hexsha": "3110d5d818cb8fdfb4959e58d9dcbc48db325122", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-02-28T03:44:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-10T05:32:54.000Z", "avg_line_length": 23.1282051282, "max_line_length": 72, "alphanum_fraction": 0.6363636364, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574129515172, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.8358616976877355}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c trapezoidal.f95\n! gfortran -o trapezoidal trapezoidal.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\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\nprogram trapz\n implicit none\n real :: xi,xf,xn,h,lt,li,f\n real,dimension (1000) :: x,fa,fori,result,estimate_i,er\n integer :: i,j,n\n character(len=100) :: save_file\n\n write(*,*)\"\"\n write(*,*)\"--------------------------------\"\n write(*,*)\"TRAPEZOIDAL METHOD - INTEGRATION\"\n write(*,*)\"--------------------------------\"\n write(*,*) \"\"\n write(*,\"(a)\",advance=\"no\") \"Insert Initial Boundary (XI):\"\n read*, xi\n write(*,\"(a)\",advance=\"no\") \"Insert Final Boundary (XF):\"\n read*, xf\n write(*,\"(a)\",advance=\"no\") \"Insert Data Length (ex: N=100):\"\n read*, n\n\n write(*,*)\"\"\n ! Calculate step data point\n h = (xf-xi)/n\n ! Generate the data with h step data point and subtitute in original function\n x(1) = xi\n do i = 1,n\n x(i+1) = x(i) + h\n fori(i) = f(x(i))\n end do\n\n ! Sum the second part of the trapezoidal equation\n fa(1) = f(xi)\n do j = 1,n-1\n fa(j+1) = fa(j) + f(x(j+1))\n end do\n\n ! Calculate the trapezoidal integration\n do i = 1,n\n result(i) = (h/2)*(f(xi) + (2*fa(i)) + f(xf))\n end do\n\n ! Calculate error between final result(n) with each iteration\n do i = 1,n\n er(i) = abs((result(n)-result(i))/result(n))*100\n end do\n\n write(*,*) \"Trapezoidal Integration Result: \", result(n)\n write(*,*) \"error: \",er(n), \" %\"\n write(*,*) \"\"\n\n ! Save integration result to file\n save_file = 'trapz.txt'\n open (10,file=save_file,status='replace')\n do i = 1,n\n write(10,*) i,x(i),fori(i),result(i),er(i)\n end do\n write(*,*)\"Result has been saved in > \",save_file\n write(*,*) \"\"\n close(10)\nend program\n\nreal function f(x)\n implicit none\n real :: x\n f = 0.2 + (25*x) - (200*(x**2)) + (675*(x**3)) - (900*(x**4)) + (400*(x**5))\n ! f = 2*x\nend function\n", "meta": {"hexsha": "a73c93944d4561b56b9e0528ab2dc7aacc85d7be", "size": 2062, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "trapezoidal.f95", "max_stars_repo_name": "auliakhalqillah/Trapezoidal-Integration-Method", "max_stars_repo_head_hexsha": "5490ca6c931f83440c02657f1bc089ae122ce583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "trapezoidal.f95", "max_issues_repo_name": "auliakhalqillah/Trapezoidal-Integration-Method", "max_issues_repo_head_hexsha": "5490ca6c931f83440c02657f1bc089ae122ce583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "trapezoidal.f95", "max_forks_repo_name": "auliakhalqillah/Trapezoidal-Integration-Method", "max_forks_repo_head_hexsha": "5490ca6c931f83440c02657f1bc089ae122ce583", "max_forks_repo_licenses": ["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.1315789474, "max_line_length": 80, "alphanum_fraction": 0.5615906887, "num_tokens": 697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8976952852648487, "lm_q1q2_score": 0.835267985630679}} {"text": "MODULE GROUND\n\t!Different ground profiles\n \tUSE NRTYPE\n \tIMPLICIT NONE\n \t!-----------------------------------------------------------\n \tCONTAINS\n \t!-----------------------------------------------------------\n\t!Gaussian Hill (Default)\n \tFUNCTION GHILL(H0,X0,S,X) RESULT(H)\n \tIMPLICIT NONE\n \tREAL(DP), INTENT(IN) :: H0, x0, s, x\n \tREAL(DP) :: H\n \tH = H0*EXP(-(x-x0)**2/s**2)\n \tEND FUNCTION GHILL\n \t!-----------------------------------------------------------\n\t!Symmetric Triangular Hill\n \tFUNCTION STHILL(H0,X0,D,X) RESULT(H)\n \tIMPLICIT NONE\n \tREAL(DP), INTENT(IN) :: H0, X0, D, X\n \tREAL(DP) :: H\n \tIF ((X.LE.(X0-D)).OR.(X.GE.(X0+D))) THEN\n \t\tH = 0\n\tELSEIF (X.LE.X0) THEN\n\t\tH = H0*((X-X0)/D+1)\n\tELSEIF (X.GT.X0) THEN\n\t\tH = H0*((X0-X)/D+1)\n\tENDIF\n\tEND FUNCTION STHILL\n \t!-----------------------------------------------------------\n\t!Unsymmetric Triangular Hill\n\tFUNCTION THILL(H0,X0,D1,D2,X) RESULT(H)\n \tIMPLICIT NONE\n \tREAL(DP), INTENT(IN) :: H0, X0, D1, D2, X\n \tREAL(DP) :: H\n \tIF ((X.LE.(X0-D1)).OR.(X.GE.(X0+D2))) THEN\n \t\tH = 0\n\tELSEIF (X.LE.X0) THEN\n\t\tH = H0*((X-X0)/D1+1)\n\tELSEIF (X.GT.X0) THEN\n\t\tH = H0*((X0-X)/D2+1)\n\tENDIF \n\tEND FUNCTION THILL\n\t!-----------------------------------------------------------\t\n\t!Rectangular Hill\n\tFUNCTION RHILL(H0,X1,X2,X) RESULT(H)\n\tIMPLICIT NONE\n\tREAL(DP), INTENT(IN) :: H0, X1, X2, X\n\tREAL(DP) :: H\n\tIF ((X.LT.X1).OR.(X.GT.X2)) THEN\n\t\tH = 0\n\tELSE\n\t\tH = H0\n\tENDIF\n\tEND FUNCTION RHILL\n \t!-----------------------------------------------------------\n\t!Slope\n\tFUNCTION SLOPE(H1,H2,X1,X2,X) RESULT(H)\n \tIMPLICIT NONE\n \tREAL(DP), INTENT(IN) :: H1, H2, X1, X2, X\n \tREAL(DP) :: H\n \tIF ((X.LT.X1).OR.(X.GT.X2)) THEN\n\t\tH = 0\n\tELSE\n\t\tH = ((H2-H1)*X+X2*H1-X1*H2)/(X2-X1)\n\tENDIF \n\tEND FUNCTION SLOPE\n\t!-----------------------------------------------------------\n!\tFUNCTION REALTERR\n!\tEND FUNCTION REALTERR\n \t!-----------------------------------------------------------\nEND MODULE GROUND\n", "meta": {"hexsha": "d9e15c0d1ab7a2c047dd91fad059534b2e9a7768", "size": 1925, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/PERF/ground.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/PERF/ground.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/PERF/ground.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": 26.7361111111, "max_line_length": 62, "alphanum_fraction": 0.4483116883, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802364, "lm_q2_score": 0.880797081106935, "lm_q1q2_score": 0.8351317479939318}} {"text": "module bspline\n use num_integration\n use utils, only : wp\n\n implicit none\n\ncontains\n\n !--------------------\n ! New implementation\n !--------------------\n function cubic_spline_basis(x)\n real(wp) :: cubic_spline_basis\n real(wp), intent(in) :: x\n\n if ( x <= -2.0 ) then\n cubic_spline_basis = 0\n elseif ( -2.0 < x .and. x <= -1.0 ) then\n cubic_spline_basis = (1.0/4.0)*(2.0+x)**3\n elseif ( -1.0 < x .and. x <= 0.0 ) then\n cubic_spline_basis = (1.0/4.0)*((2.0+x)**3 - 4*(1.0+x)**3)\n elseif ( 0.0 < x .and. x <= 1.0 ) then\n cubic_spline_basis = (1.0/4.0)*((2.0-x)**3 - 4.0*(1-x)**3)\n elseif ( 1.0 < x .and. x <= 2.0 ) then\n cubic_spline_basis = (1.0/4.0)*(2.0-x)**3\n elseif( 2.0 < x ) then\n cubic_spline_basis = 0\n end if\n\n end function cubic_spline_basis\n\n function cubic_spline_basis_deriv(x)\n real(wp) :: cubic_spline_basis_deriv\n real(wp), intent(in) :: x\n\n if ( x <= -2.0 ) then\n cubic_spline_basis_deriv = 0.0\n elseif ( -2.0 < x .and. x <= -1.0 ) then\n cubic_spline_basis_deriv = (1.0/4.0)*3.0*(2.0+x)**2\n elseif ( -1.0 < x .and. x <= 0.0 ) then\n cubic_spline_basis_deriv = -(1.0/4.0)*((9*x**2)+(12*x))\n elseif ( 0.0 < x .and. x <= 1.0 ) then\n cubic_spline_basis_deriv = (1.0/4.0)*(3*x*(3*x-4.0))\n elseif ( 1.0 < x .and. x <= 2.0 ) then\n cubic_spline_basis_deriv = -(1.0/4.0)*3.0*(2.0-x)**2\n elseif( 2.0 < x ) then\n cubic_spline_basis_deriv = 0.0\n end if\n\n end function cubic_spline_basis_deriv\n\n function linear_spline_basis(x)\n real(wp) :: linear_spline_basis\n real(wp), intent(in) :: x\n\n if ( x < -1.0 .or. x > 1.0 ) then\n linear_spline_basis = 0.0\n elseif ( x <= 0.0 ) then\n linear_spline_basis = (x+1.0)\n elseif ( x <= 1.0 ) then\n linear_spline_basis = (1.0-x)\n end if\n\n end function linear_spline_basis\n\n ! ------------------\n ! Old implementation\n ! ------------------\n function linear_spline(y,x)\n !---------------\n ! Variables\n !---------------\n ! y are the three points on top of which\n ! the linear spline sits. Everywhere else\n ! it is zero.\n ! x is used for computing the desired value\n ! this spline assumes in this given point.\n real(wp), intent(in) :: y(3),x\n real(wp) :: h\n real(wp) :: linear_spline\n h = y(2) - y(1)\n linear_spline = 0\n\n if ( x < y(1) ) then\n linear_spline = 0\n elseif ( x <= y(2) ) then\n linear_spline = (x - y(1))/h\n elseif ( x <= y(3) ) then\n linear_spline = (y(3) - x)/h\n end if\n end function linear_spline\n\n function linear_spline_deriv(y,x)\n !---------------\n ! Variables\n !---------------\n ! y are the three points on top of which\n ! the linear spline sits. Everywhere else\n ! it is zero.\n ! x is used for computing the desired value\n ! this spline assumes in this given point.\n real(wp), intent(in) :: y(3),x\n real(wp) :: h\n real(wp) :: linear_spline_deriv\n h = y(2) - y(1)\n linear_spline_deriv = 0.0_wp\n\n if ( x < y(1) ) then\n linear_spline_deriv = 0\n elseif ( x <= y(2) ) then\n linear_spline_deriv = 1.0_wp/h\n elseif ( x <= y(3) ) then\n linear_spline_deriv = -1.0_wp/h\n end if\n end function linear_spline_deriv\n\n function cubic_spline(y, x)\n !---------------\n ! Variables\n !---------------\n ! y are the five points on top of which\n ! the cubi spline sits. Everywhere else\n ! it is zero.\n ! x is used for computing the desired value\n ! this spline assumes in this given point.\n real(wp), intent(in) :: y(5), x\n real(wp) :: h\n integer :: i,j\n real(wp) :: cubic_spline\n\n h = y(2) - y(1)\n if ( x < y(1) .or. x > y(5)) then\n cubic_spline = 0\n\n elseif ( x >= y(1) .and. x < y(2) ) then\n cubic_spline = ((x-y(1))**3)/(6*h**3)\n\n elseif ( x >= y(2) .and. x < y(3) ) then\n cubic_spline = &\n ( ((x-y(1))**2)*(y(3)-x) &\n + (x-y(1))*(y(4)-x)*(x-y(2)) &\n + ( (y(5)-x)*(x-y(2))**2 ) )/(6*h**3)\n\n elseif ( x >= y(3) .and. x < y(4) ) then\n cubic_spline = &\n ( (y(5)-x)*(x-y(2))*(y(4)-x) &\n + ((y(5)-x)**2)*(x-y(3)) &\n + (x-y(1))*(y(4)-x)**2 )/(6*h**3)\n\n elseif ( x >= y(4) .and. x < y(5) ) then\n cubic_spline = ((y(5)-x)**3)/(6*h**3)\n\n end if\n\n end function cubic_spline\n\n function cubic_spline_deriv(y, x)\n !---------------\n ! Variables\n !---------------\n ! y are the five points on top of which\n ! the cubi spline sits. Everywhere else\n ! it is zero.\n ! x is used for computing the desired value\n ! this spline assumes in this given point.\n real(wp), intent(in) :: y(5), x\n real(wp) :: h\n integer :: i,j\n real(wp) :: cubic_spline_deriv\n\n h = y(2) - y(1)\n if ( x < y(1) .or. x > y(5)) then\n cubic_spline_deriv = 0.0_wp\n\n elseif ( x >= y(1) .and. x < y(2) ) then\n cubic_spline_deriv = ((x-y(1))**2)/(2*h**3)\n\n elseif ( x >= y(2) .and. x < y(3) ) then\n cubic_spline_deriv = &\n - (9*x**2 - ( 2*y(5) + 2*y(4) + 2*y(3) + 6*y(2) + 6*y(1))*x &\n + 2*y(2)*y(5) &\n +( y(2) + y(1) )*y(4) + 2*y(1)*y(3) &\n + y(2)**2 + y(1)*y(2) + y(1)**2) / (6*h**3)\n\n elseif ( x >= y(3) .and. x < y(4) ) then\n cubic_spline_deriv = &\n (9*x**2 - ( 6*y(5) + 6*y(4) + 2*y(3) + 2*y(2) + 2*y(1) )*x &\n + y(5)**2 &\n + ( y(4)+2*y(3)+y(2) )*y(5) + y(4)**2 &\n + ( y(2)+2*y(1) )*y(4)) / (6*h**3)\n\n elseif ( x >= y(4) .and. x < y(5) ) then\n cubic_spline_deriv = (-(y(5)-x)**2)/(2*h**3)\n\n end if\n end function cubic_spline_deriv\n\nend module bspline\n", "meta": {"hexsha": "da0c9e598638f014bb3af7c1a91e44da04ad9876", "size": 5604, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "bspline.f95", "max_stars_repo_name": "AndreTGMello/numerical-analysis-course", "max_stars_repo_head_hexsha": "e2b4b6e7c74e8db9f4f637e7bab5b73ef119a23f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bspline.f95", "max_issues_repo_name": "AndreTGMello/numerical-analysis-course", "max_issues_repo_head_hexsha": "e2b4b6e7c74e8db9f4f637e7bab5b73ef119a23f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bspline.f95", "max_forks_repo_name": "AndreTGMello/numerical-analysis-course", "max_forks_repo_head_hexsha": "e2b4b6e7c74e8db9f4f637e7bab5b73ef119a23f", "max_forks_repo_licenses": ["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.1608040201, "max_line_length": 69, "alphanum_fraction": 0.5069593148, "num_tokens": 2078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.8350370932703306}} {"text": "\nmodule modpk_rng\n !Module that contains routines for random number generation.\n !Some of this has been taken (where indicated) from\n !RosettaCode.org and from other sites on the net.\n use modpkparams, only : dp\n implicit none\n\ninterface init_random_seed\n\tmodule procedure init_random_seed_parallel\n\tmodule procedure init_random_seed_serial\nend interface\n\ninterface shuffle\n\tmodule procedure shuffle_dp_dimn\n\tmodule procedure shuffle_int_dimn\n\tmodule procedure shuffle_dp_1\n\tmodule procedure shuffle_int_1\nend interface\n\ninterface normal\n module procedure normal_array\n module procedure normal_scalar\nend interface\n\n!Default to public.\n\n\ncontains\n\n!Generate an array of n numbers sampled from a Gaussian normal distribution with mean and standard deviation given.\n!Adapted from RosettaCode.org.\nfunction normal_array(n,mean,std) result(normal)\n implicit none\n\n integer, intent(in) :: n\n integer :: i\n real(dp) :: normal(n), temp\n real(dp), intent(in) :: mean, std\n real(dp), parameter :: pi = 4.0*ATAN(1.0)\n\n !Get uniform distribution.\n call random_number(normal)\n\n !Now convert to normal distribution\n do i = 1, n-1, 2\n temp = std * SQRT(-2.0*LOG(normal(i))) * COS(2*pi*normal(i+1)) + mean\n normal(i+1) = std * SQRT(-2.0*LOG(normal(i))) * SIN(2*pi*normal(i+1)) + mean\n normal(i) = temp\n end do\n\nend function normal_array\n\n!Generate a scalar sampled from a Gaussian normal distribution with mean and standard deviation given.\n!Adapted from RosettaCode.org.\nfunction normal_scalar(mean,std) result(scalar)\n implicit none\n\n integer :: i\n integer, parameter :: n=4\n real(dp) :: normal(n), temp, scalar\n real(dp), intent(in) :: mean, std\n real(dp), parameter :: pi = 4.0*ATAN(1.0)\n\n !Get uniform distribution.\n call random_number(normal)\n\n !Now convert to normal distribution\n do i = 1, n-1, 2\n temp = std * SQRT(-2.0*LOG(normal(i))) * COS(2*pi*normal(i+1)) + mean\n normal(i+1) = std * SQRT(-2.0*LOG(normal(i))) * SIN(2*pi*normal(i+1)) + mean\n normal(i) = temp\n end do\n\n scalar = normal(1)\n\nend function normal_scalar\n\n!Generate a random seed based on the clock time.\n!Adapted from GNU site.\nsubroutine init_random_seed_serial()\nimplicit none\n\tinteger :: i, n, clock\n\tinteger, dimension(:), allocatable :: seed\n\n\tcall random_seed(size = n)\n\tallocate(seed(n))\n\n\tcall system_clock(count=clock)\n\n\tseed = clock + 37* (/ (i - 1, i = 1, n) /)\n\tcall random_seed(PUT = seed)\n\n\tdeallocate(seed)\nend subroutine init_random_seed_serial\n\n\n!Generate a random seed based on the clock time --- For use in parallel.\nsubroutine init_random_seed_parallel(rank)\nimplicit none\n\tinteger :: i, n, clock\n\tinteger, dimension(:), allocatable :: seed\n\tinteger, intent(in) :: rank\n\n\tcall random_seed(size = n)\n\tallocate(seed(n))\n\n\tcall system_clock(count=clock)\n\n\tseed = clock + 37*rank* (/ (i - 1, i = 1, n) /)\n\tcall random_seed(PUT = seed)\n\n\tdeallocate(seed)\nend subroutine init_random_seed_parallel\n\n\n!Subroutine to shuffle an array by Knuth Shuffle.\n!Inspired by RosettaCode.org.\nsubroutine shuffle_int_1(a)\nimplicit none\n\tinteger, intent(inout) :: a(:)\n\tinteger :: i, randpos, temp\n\treal :: r\n\n\t!Count backwards\n\tdo i = size(a), 2, -1\n\t\t!Get a random number.\n\t\tcall random_number(r)\n\t\trandpos = int(r * i) + 1\n\t\t!Exchange the rows.\n\t\ttemp = a(randpos)\n\t\ta(randpos) = a(i)\n\t\ta(i) = temp\n\tend do\n\nend subroutine shuffle_int_1\n\nsubroutine shuffle_dp_dimn(a)\n implicit none\n\n real(dp), dimension(:,:), intent(inout) :: a\n\treal(dp), dimension(size(a,2)) :: temp\n\tinteger :: i, hold\n\treal(dp) :: rand\n\n\t!Count backwards.\n\tdo i=size(a,1), 1, -1\n\t\t!Generate a random int from 1-i.\n\t\tcall random_number(rand)\n\t\thold=int(rand*i)+1\n\t\t!Swap the ith row with the rand row.\n\t\ttemp(:)=a(hold,:)\n\t\ta(hold,:)=a(i,:)\n\t\ta(i,:) = temp(:)\n\tend do\n\nend subroutine shuffle_dp_dimn\n\nsubroutine shuffle_dp_1(a)\n implicit none\n\n\treal(dp), dimension(:), intent(inout) :: a\n\treal(dp) :: temp\n\tinteger :: i, hold\n\treal(dp) :: rand\n\n\t!Count backwards.\n\tdo i=size(a,1), 1, -1\n\t\t!Generate a random int from 1-i.\n\t\tcall random_number(rand)\n\t\thold=int(rand*i)+1\n\t\t!Swap the ith row with the rand row.\n\t\ttemp=a(hold)\n\t\ta(hold)=a(i)\n\t\ta(i) = temp\n\tend do\n\nend subroutine shuffle_dp_1\n\nsubroutine shuffle_int_dimn(a)\n implicit none\n\n\tinteger, dimension(:,:), intent(inout) :: a\n\tinteger, dimension(size(a,2)) :: temp\n\tinteger :: i, hold\n\treal(dp) :: rand\n\n\t!Count backwards.\n\tdo i=size(a,1), 1, -1\n\t\t!Generate a random int from 1-i.\n\t\tcall random_number(rand)\n\t\thold=int(rand*i)+1\n\t\t!Swap the ith row with the rand row.\n\t\ttemp(:)=a(hold,:)\n\t\ta(hold,:)=a(i,:)\n\t\ta(i,:) = temp(:)\n\tend do\n\nend subroutine shuffle_int_dimn\n\n!Subroutine that takes two sets, shuffles them together n times, then divides them along the columns, returning same sized arrays that are a mix of both sets.\nsubroutine shuffle_cut(setA, setB, n)\n implicit none\n\n\treal(dp), dimension(:,:), intent(inout) :: setA, setB\n\tinteger, optional, intent(in) :: n\n\treal(dp), dimension((size(setA,1)+size(setB,1)),size(setA,2)) :: work\n\treal(dp) :: rand\n\tinteger :: i, iend\n\n\t!Load the work function.\n\tdo i=1,size(work,1)\n\t\tif (i .le. size(setA,1)) then\n\t\t\twork(i,:)=setA(i,:)\n\t\telse\n\t\t\twork(i,:)=setB(i-size(setA,1),:)\n\t\tend if\n\tend do\n\n\t!Shuffle the set.\n\tif (present(n)) then\n\t\tiend=n\n\telse\n\t\tiend=2\n\tend if\n\tdo i=1,iend\n\t\tcall shuffle(work)\n\tend do\n\n\t!Unload work.\n\tdo i=1,size(work,1)\n\t\tif (i .le. size(setA,1)) then\n\t\t\tsetA(i,:)=work(i,:)\n\t\telse\n\t\t\tsetB(i-size(setA,1),:)=work(i,:)\n\t\tend if\n\tend do\n\nend subroutine shuffle_cut\n\n\n!Function to make a cluster of \"n\" points centered at \"center\" with given std \"sigma.\"\nfunction make_blob(n, center, sigma)\n implicit none\n\n\treal(dp), dimension(:), intent(in) :: center\n\treal(dp), optional, intent(in) :: sigma\n\treal(dp):: std\n\tinteger, intent(in) :: n\n\treal(dp), dimension(:,:), allocatable :: make_blob\n\tinteger :: i,j\n\n\t!Optional argument for standard deviation.\n\tif (present(sigma)) then\n\t\tstd = sigma\n\telse\n\t\tstd = 1e0_dp\n\tend if\n\n\tcall init_random_seed()\n\n\tallocate(make_blob(n,size(center)))\n\n\tdo j=1,size(center)\n\t\tmake_blob(:,j) = normal(n,center(j),std)\n\tend do\n\nend function make_blob\n\nfunction rand_sign() result(sign)\n\n real(dp) :: sign\n real(dp) :: rand\n\n call random_number(rand)\n\n if (rand >0.5) then\n sign = -1.0e0_dp\n else\n sign = 1.0e0_dp\n end if\n\nend function rand_sign\n\n\nend module modpk_rng\n", "meta": {"hexsha": "1e981df1c0f564a5e69f81168ce50fd561cc8d8e", "size": 6327, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modpk_rng.f90", "max_stars_repo_name": "laynep/MultiModeCode", "max_stars_repo_head_hexsha": "641153ce3f47d58e99bc2c9f1570874d034a029d", "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": "modpk_rng.f90", "max_issues_repo_name": "laynep/MultiModeCode", "max_issues_repo_head_hexsha": "641153ce3f47d58e99bc2c9f1570874d034a029d", "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": "modpk_rng.f90", "max_forks_repo_name": "laynep/MultiModeCode", "max_forks_repo_head_hexsha": "641153ce3f47d58e99bc2c9f1570874d034a029d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-02T13:39:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-02T13:39:29.000Z", "avg_line_length": 22.0452961672, "max_line_length": 158, "alphanum_fraction": 0.6870554765, "num_tokens": 1914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8918110396870287, "lm_q1q2_score": 0.8349892996629599}} {"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=pi/2\n REAL(rprec), PARAMETER :: twopi=2*pi\n REAL(rprec), PARAMETER :: sqrt2=1.41421356237309504880168872_rprec\n REAL(rprec), PARAMETER :: degree=twopi / 360\n REAL(rprec), PARAMETER :: one=1\n REAL(rprec), PARAMETER :: zero=0\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": "9e479ac0950328ec75bfc14c97e6fc5954d0c0f0", "size": 842, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/LIBSTELL/Sources/Modules/stel_constants.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_49", "max_stars_repo_head_hexsha": "9f1954d83b2db13f4f4b58676badda4425caeeee", "max_stars_repo_licenses": ["MIT"], "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/LIBSTELL/Sources/Modules/stel_constants.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_49", "max_issues_repo_head_hexsha": "9f1954d83b2db13f4f4b58676badda4425caeeee", "max_issues_repo_licenses": ["MIT"], "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/LIBSTELL/Sources/Modules/stel_constants.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_49", "max_forks_repo_head_hexsha": "9f1954d83b2db13f4f4b58676badda4425caeeee", "max_forks_repo_licenses": ["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.0833333333, "max_line_length": 72, "alphanum_fraction": 0.4406175772, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517095103498, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.8349005873179206}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c falseposition.f95\n! gfortran -o falseposition falseposition.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 implicit none\n real :: xi,xf,xr,error,xrold,f,limiterror\n real :: start,finish\n integer :: iter, condition\n character(len=100) :: fmt\n \n write(*,*)\"\"\n write(*,*)\"---------------------------------\"\n write(*,*)\"FALSE POSITION - FINDING ROOT\"\n write(*,*)\"---------------------------------\"\n write(*,*) \"\"\n write(*,\"(a)\",advance=\"no\") \"Insert Initial Boundary (XI):\"\n read*, xi\n write(*,\"(a)\",advance=\"no\") \"Insert Final Boundary (XF):\"\n read*, xf\n \n fmt = \"(a12,a13,a13,a20,a13,a17,a20,a17,a17,a20)\"\n write(*,*)\"\"\n \n ! Start root calculation\n call cpu_time(start)\n limiterror = 1e-20\n open(20, file='falsepoint.txt', status='replace')\n iter = 1\n xrold = xi\n ! Calculate the root by using false position method (secant method approximation)\n xr = xf - ((f(xf)*(xf-xi))/(f(xf)-f(xi)))\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 by using bisection approximation \n if ((f(xi)*f(xr)) < 0) then\n xf = xr\n xrold = xr\n xr = xf - ((f(xf)*(xf-xi))/(f(xf)-f(xi)))\n if (xr == 0) then \n error = 100\n else\n error = abs((xr-xrold)/xr) * 100\n end if\n condition = 1\n ! Check second condition by using bisection approximation \n elseif ((f(xi)*f(xr)) > 0) then\n xi = xr\n xrold = xr\n xr = xf - ((f(xf)*(xf-xi))/(f(xf)-f(xi)))\n if (xr == 0) then \n error = 100\n else\n error = abs((xr-xrold)/xr) * 100\n end if\n condition = 2\n ! Check third condition by using bisection approximation \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 if (xr == 0) then \n error = 100\n else\n error = abs((xr-xrold)/xr) * 100\n end if\n condition = 3\n end if\n iter = iter + 1\n end do\n close(20)\n call cpu_time(finish)\n print '(\"Time = \",f12.8,\" seconds.\")',finish-start\n end program\n \n function f(x)\n implicit none\n real::x,f\n ! f = (x**2)-16\n f = (x**2)-(2*x)+1\n ! f = (x**3) - (x**2) - (10*x) + 2\n end\n \n", "meta": {"hexsha": "1add3bad3deddb32f1bbf3f96f69982e1d2ce796", "size": 3396, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "falseposition.f95", "max_stars_repo_name": "auliakhalqillah/False-Position-Method", "max_stars_repo_head_hexsha": "9012da42c85d9f4864f55c12140e6d78d573bf38", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "falseposition.f95", "max_issues_repo_name": "auliakhalqillah/False-Position-Method", "max_issues_repo_head_hexsha": "9012da42c85d9f4864f55c12140e6d78d573bf38", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "falseposition.f95", "max_forks_repo_name": "auliakhalqillah/False-Position-Method", "max_forks_repo_head_hexsha": "9012da42c85d9f4864f55c12140e6d78d573bf38", "max_forks_repo_licenses": ["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.6530612245, "max_line_length": 99, "alphanum_fraction": 0.4522968198, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.9086179037377832, "lm_q1q2_score": 0.8345475919233033}} {"text": "program main\n use LinearSolverClass\n implicit none\n\n ! Create Ax=B and solve x = A^(-1) B\n integer(int32), parameter :: N = 4 ! rank = 3\n real(real64) :: t1,t2 ! time measure\n real(real64) :: A(1:N,1:N), B(1:N), X(1:N) ! A, x and B\n real(real64) :: Val(1:10) \n integer(int32) :: index_i(1:10),index_j(1:10)\n type(LinearSolver_) :: solver ! linear solver instance.\n\n ! creating A, x, and B\n A(1,1:4) = (/ 2.0d0, -1.0d0, 0.0d0, 0.0d0 /)\n A(2,1:4) = (/ -1.0d0, 2.0d0, -1.0d0, 0.0d0 /)\n A(3,1:4) = (/ 0.0d0, 2.0d0, 3.0d0, 1.0d0 /)\n A(4,1:4) = (/ 0.0d0, 0.0d0, 1.0d0, 2.0d0 /)\n\n X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n\n B(1:4) = (/ 1.0d0, 2.0d0, 3.0d0, 4.0d0 /)\n\n ! CRS-format\n Val(1:10) = (/ 2.0d0, -1.0d0, -1.0d0, 2.0d0, -1.0d0, 2.0d0, 3.0d0, &\n 1.0d0, 1.0d0, 2.0d0/)\n index_i(1:10) = (/ 1, 1, 2, 2, 2, 3, 3, 3, 4, 4/)\n index_j(1:10) = (/ 1, 2, 1, 2, 3, 2, 3, 4, 3, 4/)\n\n ! import Ax=B into the linear solver instance.\n call solver%import(a = A, x = X, b = B)\n\n ! get a cpu-time\n call cpu_time(t1) \n ! solve Ax=B by Gauss-Jordan\n call solver%solve(Solver=\"GaussJordan\")\n ! get a cpu-time\n call cpu_time(t2) \n ! show result\n ! X is stored in solver%X(:) (solver.x[])\n print *, \"Solved by GaussJordan\",solver%X(:),\"/\",t2-t1,\" sec.\"\n\n ! Similarly ...\n\n X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = A, x = X, b = B, val=val, index_i=index_i, index_j=index_j)\n call cpu_time(t1) \n call solver%solve(Solver=\"GaussSeidel\")\n call cpu_time(t2) \n print *, \"Solved by GaussSeidel\",solver%X(:),\"/\",t2-t1,\" sec.\"\n \n X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = A, x = X, b = B, val=val, index_i=index_i, index_j=index_j)\n call cpu_time(t1) \n call solver%solve(Solver=\"BiCGSTAB\",CRS=.true.)\n call cpu_time(t2) \n print *, \"Solved by BiCGSTAB(CRS)\",solver%X(:),\"/\",t2-t1,\" sec.\"\n\n X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = A, x = X, b = B, val=val, index_i=index_i, index_j=index_j)\n call cpu_time(t1) \n call solver%solve(Solver=\"BiCGSTAB\",CRS=.false.)\n call cpu_time(t2) \n print *, \"Solved by BiCGSTAB \",solver%X(:),\"/\",t2-t1,\" sec.\"\n\n X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = A, x = X, b = B)\n call cpu_time(t1) \n call solver%solve(Solver=\"GPBiCG\")\n call cpu_time(t2) \n print *, \"Solved by GPBiCG \",solver%X(:),\"/\",t2-t1,\" sec.\"\n \n ! Under construction!\n !X(1:3) = (/ 0.0d0, 0.0d0, 0.0d0 /)\n !call solver%import(a = A, x = X, b = B)\n !call cpu_time(t1) \n !call solver%solve(Solver=\"GPBiCG\",preconditioning=.true.)\n !call cpu_time(t2) \n !print *, \"Solved by pre-GPBiCG \",solver%X(:),\"/\",t2-t1,\" sec.\"\nend program", "meta": {"hexsha": "45c1c32763c01d6333b8aa17a667ea156207afe3", "size": 2857, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/app/std/linear_solver_ex1.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorial/app/std/linear_solver_ex1.f90", "max_issues_repo_name": "kazulagi/plantfem_min", "max_issues_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_issues_repo_licenses": ["MIT"], "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/app/std/linear_solver_ex1.f90", "max_forks_repo_name": "kazulagi/plantfem_min", "max_forks_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_forks_repo_licenses": ["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.164556962, "max_line_length": 86, "alphanum_fraction": 0.5365768288, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.8902942290328345, "lm_q1q2_score": 0.8343933652188223}} {"text": "! File: MATH_FUNCS.f95\n! \n! Provides root-finding capability in Fortran for cubic equations by \n! an analytical solution, based on equations at:\n! http://en.wikipedia.org/wiki/Cubic_function\n! \n! S. Socolofsky\n! June 2013\n! Texas A&M University\n! \n\nmodule Math_Constants\n \n ! Define constants for use by the contained math routines\n implicit none\n integer, parameter :: DP = 8\n \nend module Math_Constants\n \nsubroutine cubic_roots(p, x0)\n \n ! \n ! Computes the roots of a cubic polynomial with coefficients p().\n ! \n ! Computes the roots of an 3rd-order polynomial with real-valued \n ! coefficients specified in p(). The order of the coefficients in \n ! p() are given by\n ! \n ! p(1) * x**3 + p(2) * x**2 + p(3) * x + p(4) = 0\n ! \n ! Input variables are:\n ! p = array (order 4) of polynomial coefficients (must be real)\n ! \n ! Output variable is:\n ! x0 = array (order 3) of roots (real or complex)\n ! \n ! S. Socolofsky\n ! June 2013\n !\n \n use Math_Constants\n implicit none\n \n ! Declare the input and output variable types\n integer, parameter :: N = 3\n real(kind = DP), intent(in), dimension(N + 1) :: p\n complex(kind = DP), intent(out), dimension(N) :: x0\n \n ! Declare the variables internal to the function\n integer :: k\n real(kind = DP) :: Delta, a, b, c, d, eps\n real(kind = DP), dimension(N) :: Dk\n complex(kind = DP), parameter :: I = cmplx(0.0, 1.0)\n complex(kind = DP) :: C0\n complex(kind = DP), dimension(N) :: u\n \n ! Extract the coefficient values for easier reference and understanding\n ! in the code\n a = p(1)\n b = p(2)\n c = p(3)\n d = p(4)\n \n ! Compute the ingredients to the solution\n Delta = 18.0D0 * a * b * c * d - 4.0D0 * b**3 * d + b**2 * c**2 - & \n & 4.0D0 * a * c**3 - 27.0D0*a**2*d**2\n Dk = [b**2 - 3.0D0 * a * c, &\n & 2.0D0 * b**3 - 9.0D0 * a * b * c + 27.0D0 * a**2 * d, &\n & -27.0D0 * a**2 * Delta]\n u = [1.0D0 + 0.0D0*I, (-1.0D0 + I * sqrt(3.0D0)) / 2.0D0, &\n & (-1.0D0 - I * sqrt(3.0D0)) / 2.0D0]\n C0 = ((Dk(2) + sqrt(Dk(3)+0.0D0*I)) / 2.0D0)**(1.0D0/3.0D0)\n \n ! Compute the solution\n x0(:) = -1.0D0 / (3.0D0 * a) * (b + u(:) * C0 + Dk(1) / (u(:) * C0))\n \n ! Get the machine precision\n eps = epsilon(0.0)\n \n ! Convert appropriately small numbers to zero\n do k = 1, N\n ! Real part first\n if (abs(real(x0(k))) < eps) then\n x0(k) = cmplx(0.0D0, aimag(x0(k)), kind = DP)\n end if\n ! And imaginary part\n if (abs(aimag(x0(k))) < eps) then\n x0(k) = cmplx(real(x0(k)), 0.0D0, kind = DP)\n end if\n end do\n \nend subroutine cubic_roots\n\n! End File: MATH_FUNCS.f95", "meta": {"hexsha": "a2a74ac5a8e2f5c6da9352242c2e3230c2d9a727", "size": 2777, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tamoc/src/math_funcs.f95", "max_stars_repo_name": "CIGOM-Modelacion/tamoc", "max_stars_repo_head_hexsha": "793fcff5ef7ddb75c182829850295a4df9cccc7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2016-02-24T01:48:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T03:18:24.000Z", "max_issues_repo_path": "tamoc/src/math_funcs.f95", "max_issues_repo_name": "CIGOM-Modelacion/tamoc", "max_issues_repo_head_hexsha": "793fcff5ef7ddb75c182829850295a4df9cccc7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 16, "max_issues_repo_issues_event_min_datetime": "2016-08-09T07:06:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-23T19:38:37.000Z", "max_forks_repo_path": "tamoc/src/math_funcs.f95", "max_forks_repo_name": "CIGOM-Modelacion/tamoc", "max_forks_repo_head_hexsha": "793fcff5ef7ddb75c182829850295a4df9cccc7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-01T01:22:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-17T12:13:40.000Z", "avg_line_length": 29.5425531915, "max_line_length": 75, "alphanum_fraction": 0.5462729564, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109756113862, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.8339635772799566}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: target_num_div = 500\n\n ! Variables\n integer(8) :: i,tri_num,num_div\n\n ! Do work\n i = 1\n tri_num = 0\n do\n tri_num = tri_num + i\n num_div = number_of_divisors(tri_num)\n\n if (num_div > target_num_div) then\n exit\n else\n i = i + 1\n endif\n enddo\n\n ! Write out answer\n write(*,*) \"Smallest triangle number with more than \",target_num_div,&\n \"divisors: \",tri_num\n\ncontains\n\n pure function number_of_divisors(i)\n ! Default\n implicit none\n\n ! Function arguments\n integer(8), intent(in) :: i\n integer(4) :: number_of_divisors\n\n ! Local variables\n integer(8) :: max_try,test\n\n\n ! Find max factor to try\n max_try = nint(sqrt(1D0*i))\n\n ! We know that 1 and the number are trivial factors\n ! Protect against the case where i==1\n ! Since we start the checks below at n==2, the case of i==2\n ! is another special case we need to deal with properly\n if (i==1) then\n number_of_divisors = 1\n return\n else if (i==2) then\n number_of_divisors = 2\n return\n else\n number_of_divisors = 2\n endif\n\n ! Check to see if a number is a divisor\n ! We are testing from 2 to sqrt(i)\n ! For each number we find, we know there is going to be a pair of factors\n ! E.g.: for the case of i=36, we test from 2 to 6\n ! mod(36,2)==0 (so we've found 2 factors: 2 and 18)\n ! mod(36,3)==0 (another 2 factors: 3 and 12)\n ! mod(36,4)==0 (4 and 9)\n ! mod(36,5)/=0 (no factors)\n ! mod(36,6)==0 (but! 36/6==6, so we have caught the perfect-square case)\n ! Add to this the trivial factors of 1 and 36, and we have found all\n ! 9 factors, while only having to test up through sqrt(36)\n test = 2\n do\n if (mod(i,test)==0) then\n ! Test for perfect-square case\n ! This should also be the end of the line, so we exit just in case\n ! rounding for max_int has introduced rouding errors\n if (i/test==test) then\n number_of_divisors = number_of_divisors + 1\n return\n else\n number_of_divisors = number_of_divisors + 2\n endif\n endif\n\n test = test + 1\n if (test > max_try) exit\n enddo\n\n return\n end function number_of_divisors\n\n\nend program main\n", "meta": {"hexsha": "40e369cdc315d4678150a19806263b373be32338", "size": 2388, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem12/problem12.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/problem12/problem12.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/problem12/problem12.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": 25.4042553191, "max_line_length": 78, "alphanum_fraction": 0.6021775544, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.8339585566557377}} {"text": "PROGRAM RectangleRuleForIntegration\n IMPLICIT NONE \n REAL:: a, b, Area\n INTEGER:: N ! N is number of points \n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter the number of points: \"\n READ(*, *) N \n WRITE(*, fmt = '(/A)') \"Enter the value of a & b\"\n READ(*, *) a, b\n\n CALL RectangleRule(a, b, Area, N)\n WRITE(*, *) \"Area under the curve is: \", Area\n\n CONTAINS\n SUBROUTINE RectangleRule(a, b, Area, N)\n IMPLICIT NONE \n REAL:: a, b, Area, h, Xi\n INTEGER:: N, i\n ! N is number of points\n h = (b-a)/(N-1)\n Area = 0.00\n DO i = 1, N-1\n Xi = a + (i-1)*h\n Area = Area + f(Xi) * h\n ENDDO\n END SUBROUTINE RectangleRule\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 RectangleRuleForIntegration", "meta": {"hexsha": "aefccca3942d6f184ffe6926316e20061166cdc1", "size": 884, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Integration/Rectangle_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/Rectangle_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/Rectangle_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.0, "max_line_length": 73, "alphanum_fraction": 0.5158371041, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030095, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.8338896829565131}} {"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 subspace iteration method \n! with Rayleigh-Ritz projection\n!\n!--------------------------------------------------------------------------------------------------------------------\n!\n!! subspace_iter_v1\n! -----------------\n!\n! routine that computes a certain amount of eigenvalues and eigenvectors of a matrix A\n! using the subspace iteration method with Rayleigh-Ritz projection (v1)\n!\n! ..Input arguments\n! n : integer, size of the matrix A\n! m : integer, size of the searched subspace\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! ..Input/Output arguments\n! v : double precision matrix, (input) the starting subspace\n! (output) the eigenvectors corresponding\n! to the dominant eigenvalues\n!\n! ..Output arguments\n! w : double precision vector, the eigenvalues\n! n_ev : integer, the number of computed eigenvalues\n! acc_ev : double precision vector, accuracy 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! -4 : problem in dsyev (ERROR)\n!-------------------------------------------------------------------------------------------------------------------\n subroutine subspace_iter_v1(n, m, a, percentage, maxit, eps, v, w, n_ev, acc_ev, it_ev, ierr)\n implicit none\n !! the subspace dimensions\n integer, intent(in) :: n, m\n !! the target matrix \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 starting subspace. The computed eigenvectors will be\n !! returned in this array\n double precision, dimension(n, m), intent(inout) :: v\n !! the m dominant eigenvalues\n double precision, dimension(m), intent(out) :: w\n !! number of computed eigenvalues\n integer, intent(out) :: n_ev\n !! accuracy 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 :: dlange, ddot\n\n ! constants\n integer, parameter :: ione = 1\n double precision, parameter :: done = 1.d0, dzero = 0.d0, dmoins = -1.d0\n\n !! local variables \n integer :: i, j\n double precision, allocatable, dimension(:,:) :: y\n double precision, allocatable, dimension(:,:) :: h, x\n double precision, allocatable, dimension(:) :: aux_acc, w_aux, t\n double precision :: trace, p_trace, eig_sum, normF_A\n integer :: conv\n integer :: k\n double precision :: acc\n logical :: ok\n double precision :: beta\n !! the length of the workspace for dsyev\n integer :: lwork\n !! the workspace \n double precision, allocatable, dimension(:) :: work\n\n ierr = 0\n\n if(m.gt.n)then\n ierr = -1\n return\n end if\n\n lwork = m*m + 5*m + n*n\n allocate(y(n, m), h(m, m), x(m, m), w_aux(m), aux_acc(n), t(m), work(lwork), stat=ierr)\n if(ierr .ne. 0) then\n ierr = -2\n return\n end if\n\n trace = 0.d0\n do i = 1, n\n trace = trace + a(i,i)\n end do\n p_trace = percentage * trace\n eig_sum = 0.d0\n \n normF_A = dlange('f', n, n, a, n, work)\n\n it_ev = 0\n acc_ev = 0.D0\n n_ev = 0\n k = 0\n\n !! Initial set of orthonormal vectors\n call gram_schmidt(v, n, m, y)\n v = y\n\n do while((eig_sum .lt. p_trace) .and. (n_ev .lt. m) .and. (k .lt. maxit))\n\n k = k + 1\n \n !! A. Compute y = a*v\n call dgemm('n','n', n, m, n, done, a, n, v, n, dzero, y, n)\n\n !! B. Orthonormalisation\n call gram_schmidt(y, n, m, v)\n\n !! C. Rayleigh-Ritz projection\n !! 1. H = V^T A V\n !! Y = A V\n call dgemm('n','n', n, m, n, done, a, n, v, n, dzero, y, n)\n !! H = V'*Y\n call dgemm('t', 'n', m, m, n, done, v, n, y, n, dzero, h, m) \n !! 2. Spectral decomposition\n call dsyev('v', 'u', m, h, m, w_aux, work, lwork, ierr) \n if( ierr .ne.0 )then\n write(*,'(\"Error in dsyev\")')\n ierr = -4\n goto 999\n end if\n\n !! Sort in the decreasing order\n !! (we suppose that all the eigen values are positve)\n do i = 1, m\n t(i) = w_aux(m-i+1)\n x(:, i) = h(:, m-i+1)\n end do\n\n !! 3. V = VX\n y = v\n call dgemm('n', 'n', n, m, m, done, y, n, x, m, dzero, v, n)\n\n !! D. Convergence analysis step\n conv = 0\n i = n_ev + 1\n !! the larger eigenvalue will converge more swiftly than \n !! those corresponding to the smaller eigenvalue.\n !! for this reason, we test the convergence in the order \n !! i=1,2,.. and stop with the first one to fail the test\n ok = .false.\n do while(.not. ok)\n if( i .gt. m) then\n ok = .true.\n else\n !!compute acc=norm(a*v(:,i) - v(:,i)*t(i),2)/lambda;\n !!--compute aux_acc=a*v(:,i) - v(:,i)*t(i)\n !!--compute acc=||aux_acc||/||a||\n aux_acc = v(:,i)\n beta = -t(i)\n call dgemv('n', n, n, done, a, n, v(1,i), ione, beta, aux_acc, ione)\n acc = sqrt(ddot(n, aux_acc, ione, aux_acc, ione))/normF_A\n ! write(*,*) i, acc\n\n if(acc.gt.eps) then\n ok = .true.\n else\n ! write(*,*) 'vector', i, 'converges', acc\n conv = conv + 1\n w(i) = t(i)\n acc_ev(i) = acc\n it_ev(i) = k\n eig_sum = eig_sum + w(i)\n i = i + 1\n if( eig_sum .ge. p_trace) ok = .true.\n end if\n end if\n end do\n\n n_ev = n_ev + conv\n !write(*,*) n_ev\n\n end do\n\n if(n_ev .eq. m) then \n ierr = 1\n end if\n if(k .eq. maxit) then\n ierr = -3\n end if\n\n999 continue\n deallocate(y, h, x, w_aux, aux_acc, t)\n write(*,*)\n \n return\n end subroutine subspace_iter_v1\n", "meta": {"hexsha": "08a1cbb9d47c783f8520679c70d3db13cb8487aa", "size": 7781, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tp2/Fortran/iter_v1.f90", "max_stars_repo_name": "Brawdunoir/ACP-Eigenfaces", "max_stars_repo_head_hexsha": "6c43ced8612f3ad5fc1fe8c355707d8083937629", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-22T18:04:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-22T18:04:20.000Z", "max_issues_repo_path": "tp2/Fortran/iter_v1.f90", "max_issues_repo_name": "Brawdunoir/ACP-Eigenfaces", "max_issues_repo_head_hexsha": "6c43ced8612f3ad5fc1fe8c355707d8083937629", "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": "tp2/Fortran/iter_v1.f90", "max_forks_repo_name": "Brawdunoir/ACP-Eigenfaces", "max_forks_repo_head_hexsha": "6c43ced8612f3ad5fc1fe8c355707d8083937629", "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.8571428571, "max_line_length": 117, "alphanum_fraction": 0.5000642591, "num_tokens": 2082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191246389617, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.8333701256030424}} {"text": "FUNCTION sinc ( x )\r\n!\r\n! Purpose:\r\n! To calculate the sinc function\r\n! sinc(x) = sin(x) / x\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\nREAL, INTENT(IN) :: x ! Value for which to evaluate sinc\r\nREAL :: sinc ! Output value sinc(x)\r\n\r\n! Data dictionary: declare local constants\r\nREAL, PARAMETER :: EPSILON = 1.0E-30 ! the smallest value for which \r\n ! to calculate SIN(x)/x\r\n\r\n! Check to see of ABS(x) > EPSILON.\r\nIF ( ABS(x) > EPSILON ) THEN\r\n sinc = SIN(x) / x\r\nELSE\r\n sinc = 1.\r\nEND IF\r\n\r\nEND FUNCTION sinc\r\n", "meta": {"hexsha": "9786b58a8518e083f6773eac016067e5d366ed77", "size": 831, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/sinc.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/sinc.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/sinc.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.7, "max_line_length": 70, "alphanum_fraction": 0.5294825511, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750360641185, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8332360125650548}} {"text": "\n! A Pythagorean triplet is a set of \n! three natural numbers, a < b < c, for which,\n! a^2 + b^2 = c^2\n! For example, 32 + 42 = 9 + 16 = 25 = 52.\n! There exists exactly one Pythagorean triplet \n! for which a + b + c = 1000.\n! Find the product abc.\n! \n! Project Euler: 9\n! Answer: 31875000\n\n\nprogram main\n\nuse euler\n\nimplicit none\n\n ! a + b + c = 1000\n ! 1000 - (a + b) = c\n\n integer (kind=8), parameter :: PERIMETER = 1000\n integer (kind=8) :: a, b, c\n\n outer: do a = 1, PERIMETER, 1\n\n inner: do b = 1, PERIMETER, 1\n \n c = PERIMETER - (a + b)\n\n if(c <= 0) then\n exit inner\n endif\n\n if(pythag_triplet(a, b, c)) then\n exit outer\n endif\n\n end do inner\n \n end do outer\n\n print*, a * b * c\n\n\ncontains\n\n\n ! Test whether a triple is pythagorean - the long way\n\n pure function pythag_triplet(a, b, c)\n\n integer (kind=8), intent(in) :: a, b, c\n logical :: pythag_triplet\n\n pythag_triplet = (a ** 2 + b ** 2 == c ** 2)\n\n return\n\n end function pythag_triplet\n\n\n ! It can be shown that;\n !\n ! 500 = (a + b) - (a*b) / 1000\n !\n ! In this notion, we can check if a*b is divisible\n ! by 1000 and then if the above equation holds\n !\n ! More generally, Perimeter / 2 = (a + b) - (a * b) / perimeter\n !\n ! @param: PERIMETER must be defined to \n\n pure function special_pythag(a, b)\n\n integer (kind=8), intent(in) :: a, b\n integer (kind=8) :: prod\n logical :: special_pythag\n\n special_pythag = .false.\n\n prod = a * b\n \n if(mod(prod, PERIMETER) /= 0) then\n return\n endif\n\n special_pythag = (PERIMETER / 2 == (a + b) - prod / PERIMETER)\n\n return\n\n end function special_pythag\n\n\nend program main\n\n", "meta": {"hexsha": "03a5dd8e7991d70900f196ed71bc02905f9ee873", "size": 2197, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/special_pythag_trip.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/special_pythag_trip.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/special_pythag_trip.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": 22.4183673469, "max_line_length": 78, "alphanum_fraction": 0.4465179791, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.8332360113062133}} {"text": "MODULE precision\n ! dp = double precision\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\nPROGRAM Secant_Method\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: x1, x2, x3, f1, f2, f3, error, root\n WRITE(*, *) \"Enter value of 2 initial point \"\n ! For this question enter 2 initial point x1 and x2\n READ *, x1, x2\n \n error = 1e-6\n f1 = Func(x1)\n f2 = Func(x2)\n\n DO\n x3 = (f2*x1 - f1*x2) / (f2 - f1)\n f3 = Func(x3)\n IF (f3 .EQ. 0.0) THEN\n root = x3\n WRITE(*, *) \"Root is: \", root\n RETURN\n ENDIF\n\n IF (abs((x3 - x2)/x3) .LT. error) THEN \n root = x3\n WRITE(*, *) \"Root is: \", root\n RETURN\n ELSE \n x1 = x2\n f1 = f2\n x2 = x3\n f2 = f3\n ENDIF\n ENDDO \n\n CONTAINS\n REAL(KIND = dp) FUNCTION Func(x)\n USE precision\n IMPLICIT NONE \n REAL(KIND = dp):: x\n Func = x**2 - 4*x - 10\n RETURN \n END FUNCTION Func\n\nEND PROGRAM Secant_Method\n", "meta": {"hexsha": "3a76b74c3e9e41ebb12e2c4b672af7f3c1135c59", "size": 1089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Roots of Nonlinear Equation/Secant Method.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": "Roots of Nonlinear Equation/Secant Method.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": "Roots of Nonlinear Equation/Secant Method.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.78, "max_line_length": 57, "alphanum_fraction": 0.4885215794, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.8331930064086334}} {"text": "program area_mandelbrot\n implicit none\n!\n integer, parameter :: sp = kind(1.0) \n integer, parameter :: dp = kind(1.0d0)\n integer :: i, j, iter, numoutside\n integer, parameter :: npoints = 4000, maxiter = 4000\n real (kind=dp) :: area, error\n complex (kind=dp) :: c , z\n real :: starttime, endtime\n!\n! Calculate area of mandelbrot set\n!\n! Outer loops runs over npoints, initialize z=c\n!\n! Inner loop has the iteration z=z*z+c, and threshold test\n!\n\n numoutside = 0 \n\n call cpu_time(starttime)\n\n do i = 0,npoints-1\n do j= 0,npoints-1 \n c = cmplx(-2.0+(2.5*i)/npoints + 1.0d-07,(1.125*j)/npoints + 1.0d-07)\n z = c\n iter = 0\n do while (iter < maxiter) \n z = z*z + c \n iter = iter + 1\n if (real(z)*real(z)+aimag(z)*aimag(z) > 4) then\n numoutside = numoutside + 1 \n exit\n endif\n end do \n end do\n end do\n\n call cpu_time(endtime)\n!\n! Output results\n!\n area = 2.0*2.5*1.125 * real(npoints*npoints-numoutside)/real(npoints*npoints)\n error = area/real(npoints)\n print *, \"Area of Mandelbrot set = \",area,\" +/- \",error\n print *, \"Tome taken for calculation: \",endtime-starttime\n!\n stop\nend program area_mandelbrot\n", "meta": {"hexsha": "eaab7e21b5d62420b1dbb1fa22b5f8a610c365c0", "size": 1236, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Code_Examples/Chapter_02/Src/Fortran/area.ser.f90", "max_stars_repo_name": "OpenACCUserGroup/openacc_concept_strategies_book", "max_stars_repo_head_hexsha": "7547260d6d845d34b1f28bbb64ab93226c705207", "max_stars_repo_licenses": ["CC-BY-4.0", "CC0-1.0"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2017-07-17T08:28:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T19:05:55.000Z", "max_issues_repo_path": "Code_Examples/Chapter_02/Src/Fortran/area.ser.f90", "max_issues_repo_name": "OpenACCUserGroup/openacc_concept_strategies_book", "max_issues_repo_head_hexsha": "7547260d6d845d34b1f28bbb64ab93226c705207", "max_issues_repo_licenses": ["CC-BY-4.0", "CC0-1.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-11-18T17:30:28.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-08T12:39:27.000Z", "max_forks_repo_path": "Code_Examples/Chapter_02/Src/Fortran/area.ser.f90", "max_forks_repo_name": "OpenACCUserGroup/openacc_concept_strategies_book", "max_forks_repo_head_hexsha": "7547260d6d845d34b1f28bbb64ab93226c705207", "max_forks_repo_licenses": ["CC-BY-4.0", "CC0-1.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-08-17T13:46:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-03T16:09:34.000Z", "avg_line_length": 24.72, "max_line_length": 79, "alphanum_fraction": 0.5922330097, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.8331679623662168}} {"text": "!program main\n! implicit real*4(a-h, o-z) ! The pppack is in single precision\n! real tau(201), c(4, 201)\n! f(x) = exp(x) * cos(2*x)\n! fderiv(x) = exp(x) * (cos(2*x) - 2 * sin(2*x))\n! ibcbeg = 2 ! Natural Cubic Spline\n! ibcend = 2\n! a = 0. ! Starting point\n! b = 2.0 ! End point\n! write(*,*) '-- Enter Number of SubIntervals --'\n! read(*,*) N\n! h = (b-a)/N ! h is the length of the subinterval\n! do i = 1, N+1\n! tau(i) = a + (i-1)*h\n! c(1, i) = f(tau(i))\n! enddo\n! c(2,1) = 0. ! Natural Cubic Spline\n! c(2,N+1) = 0. ! Natural Cubic Spline\n! call cubspl(tau, c, N, ibcbeg, ibcend)\n! ! Using the coefficient computed above, we actually\n! ! evaluate function values\n! ! at mid-points and compare with the exact values.\n! k = 4\n! jderiv = 0 ! Compute the 0-th derivative, i.e,\n! ! The function values.\n! do i= 1, N-1\n! x = a + (i+0.5)*h ! At the mid-point of the subintervals.\n! y = f(x) ! The Exact Value\n! y2 = ppvalu(tau, c, N, k, x, jderiv) ! Cubic Spline Value\n! write(*,*)' Value at x = ', x, y, y2\n! enddo\n! write(*,*) ' -- Derivatives --'\n! k = 4\n! jderiv = 1 ! Compute the 1-th derivative, i.e,\n! ! The first-derivative values.\n! do i= 1, N-1\n! x = a + (i+0.5)*h ! At the mid-point of the subintervals.\n! y = fderiv(x) ! The Exact Value\n! y2 = ppvalu(tau, c, N, k, x, jderiv) ! Cubic Spline Value\n! write(*,*)' Value at x = ', x, y, y2\n! enddo\n! stop\n!end program main\n\nprogram main\n !====================================================================\n ! Spline interpolation\n ! Comments: values of function f(x) are calculated in n base points\n ! then: spline coefficients are computed\n ! spline interpolation is computed in 2n-1 points,\n ! a difference sum|f(u)-ispline(u)|\n !====================================================================\n implicit none\n integer, parameter :: n=11 ! base points for interpolation\n integer, parameter :: nint=11 ! compute interpolation in nint points\n double precision xmin, xmax ! given interval of x()\n double precision, dimension (n) :: xi(n), yi(n), b(n), c(n), d(n)\n double precision x, y, step, ys, error, errav\n integer i\n double precision f, ispline\n\n ! open files\n !open (unit=1, file='tablex1.dat')\n !open (unit=2, file='tablex2.dat')\n\n xmin = 0.0\n xmax = 2.0\n\n ! step 1: generate xi and yi from f(x), xmin, xmax, n\n step = (xmax-xmin)/(n-1)\n do i=1,n\n xi(i) = xmin + step*float(i-1)\n yi(i) = f(xi(i))\n ! write (*,200) xi(i), yi(i)\n end do\n\n ! step 2: call spline to calculate spline coeficients\n call spline (xi, yi, b, c, d,n)\n\n ! step 3: interpolation at nint points\n errav = 0.0\n step = (xmax-xmin)/(nint-1)\n write(*,201)\n do i=1, nint\n x = xmin + step*float(i-1)\n y = f(x)\n ys = ispline(x, xi, yi, b, c, d, n)\n error = ys-y\n write (*,200) x, ys, error\n ! step 4: calculate quality of interpolation\n errav = errav + abs(y-ys)/nint\n end do\n write (*,202) errav\n 200 format (3f12.5)\n 201 format (' x spline error')\n 202 format (' Average error',f12.5)\n\nend program main\n\n\n!\n! Function f(x)\n!\nfunction f(x)\n double precision f, x\n f = exp(x) * cos(2*x)\nend function f\n\nsubroutine 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 !----------------------------------------------------------------------\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 !======================================================================\n implicit none\n integer n\n double precision x(n), y(n), b(n), c(n), d(n)\n integer i, j, gap\n double precision h\n\n gap = n-1\n ! check input\n if ( n < 2 ) return\n if ( n < 3 ) then\n b(1) = (y(2)-y(1))/(x(2)-x(1)) ! linear interpolation\n c(1) = 0.\n d(1) = 0.\n b(2) = b(1)\n c(2) = 0.\n d(2) = 0.\n return\n end if\n !\n ! step 1: preparation\n !\n d(1) = x(2) - x(1)\n c(2) = (y(2) - y(1))/d(1)\n do i = 2, gap\n d(i) = x(i+1) - x(i)np.array\n b(i) = 2.0*(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 end donp.array\n !\n ! step 2: end conditions\n !\n b(1) = -d(1)\n b(n) = -d(n-1)\n c(1) = 0.0\n c(n) = 0.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 end if\n !\n ! step 3: forward elimination\n !\n do i = 2, n\n h = d(i-1)/b(i-1)\n b(i) = b(i) - h*d(i-1)\n c(i) = c(i) - h*c(i-1)\n end do\n !\n ! step 4: back substitution\n !\n c(n) = c(n)/b(n)\n do j = 1, gap\n i = n-j\n c(i) = (c(i) - d(i)*c(i+1))/b(i)\n end do\n !\n ! step 5: compute spline coefficients\n !\n b(n) = (y(n) - y(gap))/d(gap) + d(gap)*(c(gap) + 2.0*c(n))\n do i = 1, gap\n b(i) = (y(i+1) - y(i))/d(i) - d(i)*(c(i+1) + 2.0*c(i))\n d(i) = (c(i+1) - c(i))/d(i)\n c(i) = 3.*c(i)\n end do\n c(n) = 3.0*c(n)\n d(n) = d(n-1)\nend subroutine spline\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 !=======================================================================\n implicit none\n double precision ispline\n integer n\n double precision u, x(n), y(n), b(n), c(n), d(n)\n integer i, j, k\n double precision dx\n\n ! if u is ouside the x() interval take a boundary value (left or right)\n if(u <= x(1)) then\n ispline = y(1)\n return\n end if\n if(u >= x(n)) then\n ispline = y(n)\n return\n end if\n\n !*\n ! binary search for for i, such that x(i) <= u <= x(i+1)\n !*\n i = 1\n j = n+1\n do while (j > i+1)\n k = (i+j)/2\n if(u < x(k)) then\n j=k\n else\n i=k\n end if\n end do\n !*\n ! evaluate spline interpolation\n !*\n dx = u - x(i)\n ispline = y(i) + dx*(b(i) + dx*(c(i) + dx*d(i)))\nend function ispline", "meta": {"hexsha": "db622652985277c06a60357c20b12f1954dc4124", "size": 7473, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerial_Analysis/3rd/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/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/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": 30.2550607287, "max_line_length": 76, "alphanum_fraction": 0.4608590927, "num_tokens": 2568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.8887587905460026, "lm_q1q2_score": 0.8329543341299793}} {"text": " module interpolation\n contains\n ! From Numerical Recipes Chapter 3 - Interpolation and Extrapolation - polint\n ! Polynomial Interpolation using Nevilles algorithm.\n !ms: f90tified it, +implicit none, +intent(*)\n ! Given arrays xa and ya, each of length n, and\n ! given a value x, this routine returns a value y, and\n ! an error estimate dy. If P (x) is the polynomial of\n ! degree N − 1 such that P (xai ) = yai ,\n ! i = 1, . . . , n, then the returned value y = P (x).\n SUBROUTINE polint(xa,ya,x,y,dy)\n implicit none\n !integer,intent(in) :: n\n real*8,intent(in) :: x,xa(:),ya(:)\n real*8,intent(out) :: dy,y\n !integer,parameter :: NMAX=10 ! Largest anticipated value of n.\n integer :: i,m,ns,n\n real*8 :: den,dif,dift,ho,hp,w,c(size(xa)),d(size(xa))\n ns=1\n n=size(xa)\n dif=abs(x-xa(1))\n do i=1,n ! Here we find the index ns of the closest table entry,\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) ! and initialize the tableau of c’s and d’s.\n d(i)=ya(i)\n enddo\n y=ya(ns) ! This is the initial approximation to y.\n ns=ns-1\n L13:do m=1,n-1 ! For each column of the tableau,\n do i=1,n-m ! we loop over the current c’s and d’s and update them.\n ho=xa(i)-x\n hp=xa(i+m)-x\n w=c(i+1)-d(i)\n den=ho-hp\n ! This error can occur only if two input xa’s are (to within roundoff) identical.\n if(den.eq.0.) stop 'polint: failure: xa not unique'\n den=w/den\n d(i)=hp*den ! Here the c’s and d’s are updated.\n c(i)=ho*den\n enddo\n if (2*ns.lt.n-m)then ! After each column in the tableau is completed, we decide\n dy=c(ns+1) ! which correction, c or d, we want to add to our accu-\n else ! mulating value of y, i.e., which path to take through\n dy=d(ns) ! the tableau—forking up or down. We do this in such a\n ns=ns-1 ! way as to take the most “straight line” route through the\n endif ! tableau to its apex, updating ns accordingly to keep track\n y=y+dy ! of where we are. This route keeps the partial approxima-\n enddo L13 ! tions centered (insofar as possible) on the target x. The\n return ! last dy added is thus the error indication.\n END SUBROUTINE POLINT\n\n FUNCTION POLINT_F(xa,ya,x) result(y)\n real*8,intent(in) :: xa(:),ya(:),x\n real*8 :: y,dy\n call polint(xa,ya,x,y,dy)\n\n END FUNCTION\n end module\n\n !PROGRAM MAIN\n ! use interpolate\n ! integer,parameter :: n=3\n ! real*8 :: xa(n),ya(n),x,y,dy\n ! do i=1,n\n ! xa(i)=i;\n ! enddo\n ! ya(1)=1; ya(2)=4; ya(3)=9; ya(4)=16;\n !\n ! x=2.0; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=3.0; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=2.1; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=2.2; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=2.3; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=2.4; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n ! x=2.5; call polint(xa,ya,n,x,y,dy); print *,x,y,dy\n !end PROGRAM\n\n\n", "meta": {"hexsha": "f9c03dbc31727cddaf27f45121290adbdbbaeb27", "size": 3606, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/interpolation.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/interpolation.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/interpolation.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": 43.4457831325, "max_line_length": 98, "alphanum_fraction": 0.5058236273, "num_tokens": 1121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.954647415574754, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.832784165135875}} {"text": "module ode\r\n use nrtype\r\n implicit none\r\ncontains\r\n subroutine rk4g(derivs, x, yi, yf, h)\r\n !=========================================================!\r\n ! Solve n first-order ODEs or n/2 second-order. !\r\n ! Runge-Kutta 4 Gill's method !\r\n ! Daniel Celis Garza 24 Sept. 2015 !\r\n !---------------------------------------------------------!\r\n ! f(x,y,dydx) = ODEs to be solved !\r\n ! Let n := size(y) then for a k'th order system !\r\n ! y(1+i*n/k:(i+1)*n/k) := i'th order derivative !\r\n !---------------------------------------------------------!\r\n ! Inputs: !\r\n ! derivs = derivatives !\r\n ! h = step size !\r\n ! x = independent variable @ step i !\r\n ! yi() = array of dependent variables @ step i !\r\n !---------------------------------------------------------!\r\n ! Outputs: !\r\n ! yf() = array of dependent variables @ step i+1 !\r\n !---------------------------------------------------------!\r\n ! Locals: !\r\n ! ys() = array of dependent variables @ stage s of step i !\r\n ! ki() = array of Runge-Kutta k/h !\r\n ! ho2 = h/2 !\r\n ! ci = Butcher table parameters !\r\n !=========================================================!\r\n implicit none\r\n real(dp), intent(in) :: x, h, yi(:)\r\n real(dp), intent(out) :: yf(:)\r\n real(dp), dimension(size(yi)) :: k1, k2, k3, k4, ys\r\n real(dp) :: ho2, c1, c2, c3, c4, c5, c6, c7\r\n parameter ( c1 = sqrt(2.0_dp), c2 = -0.5_dp * c1, c3 = 2.0_dp - c1, &\r\n c4 = 2.0_dp + c1, c5 = c2 - 0.5_dp, c6 = 0.5_dp * c3, &\r\n c7 = 0.5_dp * c4 )\r\n interface derivatives\r\n subroutine derivs(x, y, dydx)\r\n use nrtype\r\n implicit none\r\n real(dp), intent(in) :: x, y(:)\r\n real(dp), intent(out) :: dydx(:)\r\n end subroutine derivs\r\n end interface derivatives\r\n\r\n ho2 = 0.5_dp * h\r\n\r\n ! Calculate k1.\r\n call derivs(x, yi, k1) ! Call the derivatives.\r\n ys = yi + ho2 * k1 ! Go through all equations and prepare for the next stage.\r\n\r\n ! Calculate k2.\r\n call derivs(x + ho2, ys, k2)\r\n ys = yi + h*(c5 * k1 + c6 * k2)\r\n\r\n ! Calculate k3.\r\n call derivs(x + ho2, ys, k3)\r\n ys = yi + h * (c2 * k2 + c7 * k3)\r\n\r\n ! Calculate k4 and yf.\r\n call derivs(x + h, ys, k4)\r\n yf = yi + h*(k1 + c3 * k2 + c4 * k3 + k4) / 6.0_dp\r\n end subroutine rk4g\r\n\r\n subroutine rkck(derivs, x, yi, yf, er, h)\r\n !=========================================================!\r\n ! Solve n first-order ODEs or n/2 second-order. !\r\n ! Cash-Karp RK45 !\r\n ! Daniel Celis Garza 24 Sept. 2015 !\r\n !---------------------------------------------------------!\r\n ! f(x,y,dydx) = ODEs to be solved !\r\n ! Let n := size(y) then for a k'th order system !\r\n ! y(1+i*n/k:(i+1)*n/k) := i'th order derivative !\r\n !---------------------------------------------------------!\r\n ! Inputs: !\r\n ! derivs = derivatives !\r\n ! h = step size !\r\n ! x = independent variable @ step i !\r\n ! yi() = array of dependent variables @ step i !\r\n !---------------------------------------------------------!\r\n ! Outputs: !\r\n ! yf() = array of dependent variables @ step i+1 !\r\n ! er() = array of integration errors !\r\n !---------------------------------------------------------!\r\n ! Locals: !\r\n ! ys() = array of dependent variables @ stage s of step i !\r\n ! ki() = array of Runge-Kutta k/h !\r\n ! ci = Butcher Table c-vector !\r\n ! aij = Butcher Table A-matrix !\r\n ! bi = Butcher Table b-vector !\r\n ! dbi = b-b* vector difference for error calculation !\r\n !=========================================================!\r\n implicit none\r\n real(dp), intent(in) :: x, yi(:), h\r\n real(dp), intent(out) :: yf(:), er(:)\r\n real(dp), dimension(size(yi)) :: k1, k2, k3, k4, k5, k6, ys\r\n real(dp) :: c2, c3, c4, c5, c6, a21, a31, a32, a41, &\r\n a42, a43, a51, a52, a53, a54, a61, a62, &\r\n a63, a64, a65, b1, b3, b4, b6, db1, db3, &\r\n db4, db5, db6\r\n parameter ( c2 = .2_dp, c3 = .3_dp, c4 = .6_dp, c5 = 1._dp, c6 = .875_dp, &\r\n a21 = .2_dp, a31 = .075_dp, a32 = .225_dp, &\r\n a41 = .3_dp, a42 = -.9_dp, a43 = 1.2_dp, &\r\n a51 = -11._dp / 54._dp, a52 = 2.5_dp, a53 = -70._dp / 27._dp, &\r\n a54 = 35._dp / 27._dp, a61 = 1631._dp / 55296._dp, &\r\n a62 = 175._dp / 512._dp, a63 = 575._dp / 13824._dp, &\r\n a64 = 44275. / 110592._dp, a65 = 253. / 4096._dp, &\r\n b1 = 37._dp / 378._dp, b3 = 250._dp / 621._dp, &\r\n b4 = 125._dp / 594._dp, b6 = 512._dp / 1771._dp, &\r\n db1 = b1-2825._dp / 27648._dp, &\r\n db3 = b3 - 18575._dp / 48384._dp, &\r\n db4 = b4 - 13525._dp / 55296._dp, &\r\n db5 = -277._dp / 14336._dp, &\r\n db6 = b6 - 0.25_dp )\r\n interface derivatives\r\n subroutine derivs(x, y, dydx)\r\n use nrtype\r\n implicit none\r\n real(dp), intent(in) :: x, y(:)\r\n real(dp), intent(out) :: dydx(:)\r\n end subroutine derivs\r\n end interface derivatives\r\n\r\n ! Calculate k1.\r\n call derivs(x, yi, k1)\r\n ys = yi + h * a21 * k1\r\n\r\n ! Calculate k2.\r\n call derivs(x + c2 * h, ys, k2)\r\n ys = yi + h * (a31 * k1 + a32 * k2)\r\n\r\n ! Calculate k3.\r\n call derivs(x + c3 * h, ys, k3)\r\n ys = yi + h * (a41 * k1 + a42 * k2 + a43 * k3)\r\n\r\n ! Calculate k4.\r\n call derivs(x + c4 * h, ys, k4)\r\n ys = yi + h * (a51 * k1 + a52 * k2 + a53 * k3 + a54 * k4)\r\n\r\n ! Calculate k5.\r\n call derivs(x + c5 * h, ys, k5)\r\n ys = yi + h * (a61 * k1 + a62 * k2 + a63 * k3 + a64 * k4 + a65 * k5)\r\n\r\n ! Calculate k6.\r\n call derivs(x + c6 * h, ys, k6)\r\n yf = yi + h * (b1 * k1 + b3 * k3 + b4 * k4 + b6 * k6)\r\n\r\n ! Calculate error.\r\n er = db1 * k1 + db3 * k3 + db4 * k4 + db5 * k5 + db6 * k6\r\n end subroutine rkck\r\n\r\n subroutine rkcka(derivs, x, y, der, h, hmin)\r\n !============================================================!\r\n ! Adaptive-step Cash-Karp RK45 !\r\n ! Daniel Celis Garza 24 Sept. 2015 !\r\n !------------------------------------------------------------!\r\n ! f(x,y,dydx) = ODEs to be solved !\r\n ! Let n := size(y) then for a k'th order system !\r\n ! y(1+i*n/k:(i+1)*n/k) := i'th order derivative !\r\n !------------------------------------------------------------!\r\n ! Inputs: !\r\n ! derivs = derivatives !\r\n ! der = desired error !\r\n !------------------------------------------------------------!\r\n ! Inputs-Outputs: !\r\n ! h = current step size !\r\n ! x = independent variable !\r\n ! y() = array of dependent variables !\r\n !------------------------------------------------------------!\r\n ! Locals: !\r\n ! loc_der = local desired error !\r\n ! ht = trial step size !\r\n ! hn = new step size !\r\n ! dydx() = array of derivatives !\r\n ! tiny = prevent division by zero !\r\n ! s = safety factor for changing h !\r\n ! shrink = (-1/(p-1)) where p is the error's order !\r\n ! grow = (-1/p) where p is the error's order !\r\n ! ercor = (5/s)**(1/grow), know when to increase h greatly !\r\n ! yscal() = scaling the error to the function's range !\r\n !============================================================!\r\n implicit none\r\n real(dp), intent(inout) :: x, y(:), h\r\n real(dp), intent(in) :: der, hmin\r\n real(dp), dimension(size(y)) :: yn, yscal, dydx, er\r\n real(dp) :: loc_der, ht, hn, maxer, tiny, &\r\n s, shrink, grow, ercor\r\n parameter ( tiny = 1.d-30, s = 0.9_dp, shrink = -0.25_dp, &\r\n grow = -0.2_dp, ercor = 1.89d-4 )\r\n interface derivatives\r\n subroutine derivs(x, y, dydx)\r\n use nrtype\r\n implicit none\r\n real(dp), intent(in) :: x, y(:)\r\n real(dp), intent(out) :: dydx(:)\r\n end subroutine derivs\r\n end interface derivatives\r\n\r\n ! Local error for numeric underflow prevention.\r\n loc_der = der\r\n call derivs(x, y, dydx)\r\n yscal = abs( y ) + abs( h * dydx ) + tiny\r\n ! When global errors are a concern use:\r\n ! yscal(:) = abs( h * dydx ) + tiny\r\n\r\n ! Integrate and Adjust H (IAH).\r\n IAH: do\r\n call rkck(derivs, x, y, yn, er, h)\r\n ! Calculate the adjusted maximum error.\r\n maxer = maxval( abs( er / yscal ) ) / loc_der\r\n ! If the maximum adjusted error is sufficiently small, exit loop.\r\n if (maxer <= 1._dp) exit IAH\r\n ! If the maximum error is too big then shrink the step size.\r\n ht = s * h * maxer ** shrink\r\n ! Prevent jumps of more than an order of magnitude.\r\n h = sign( max( abs( ht ), 0.1_dp * abs( h ) ), h)\r\n ! Prevent Numerical Underflow (PNU).\r\n PNU: if (abs( h ) < hmin .or. x + h == x) then\r\n ! This means that the error is so strict h is effectively zero,\r\n ! so the program enters an infinite loop.\r\n ! Increasing h to the minimum value.\r\n h = hmin\r\n ! By locally increasing the desired error, we further prevent the infinite loop.\r\n ! The error goes back to normal for the next integration step.\r\n loc_der = loc_der + der\r\n end if PNU\r\n end do IAH\r\n\r\n ! Check size of the maximum error.\r\n if (maxer > ercor) then\r\n ! If the maximum error is greater than an error parameter, increase it slightly.\r\n hn = s * h * maxer ** grow\r\n else\r\n ! Else, increase it greatly.\r\n hn = 5. * h\r\n end if\r\n\r\n ! Prevent numeric underflow.\r\n if(abs( hn ) < abs( hmin )) hn = hmin\r\n\r\n ! Updating for the next step.\r\n x = x + h ! Taking a step.\r\n h = hn ! Setting the next step length.\r\n y = yn ! Setting all the dependent variables to their new starting points.\r\n end subroutine rkcka\r\n\r\n subroutine basic_verlet(derivs, x, yi, yf, h)\r\n !============================================================!\r\n ! Basic Verlet Integrator (2nd order equations) !\r\n ! Daniel Celis Garza 2nd Feb. 2016 !\r\n ! This works best with constant acceleration. !\r\n !------------------------------------------------------------!\r\n ! f(x,y,dy) = ODEs to be solved !\r\n ! y = positions !\r\n !------------------------------------------------------------!\r\n ! Inputs: !\r\n ! derivs = derivatives !\r\n ! h = step size !\r\n ! x = independent variable !\r\n !------------------------------------------------------------!\r\n ! Inputs-Outputs: !\r\n ! yi() = array of dependent variables @ step i !\r\n ! yf() = array of dependent variables @ step i+1 !\r\n !------------------------------------------------------------!\r\n ! Locals: !\r\n ! dxdy() = array of derivatives !\r\n ! ys() = array of dependent variables for storage purposes !\r\n !============================================================!\r\n implicit none\r\n real(dp), intent(in) :: x, h\r\n real(dp), intent(inout) :: yi(:), yf(:)\r\n real(dp), dimension(size(yi)) :: dydx, ys\r\n real(dp) :: h2\r\n interface derivatives\r\n subroutine derivs(x, y, dydx)\r\n use nrtype\r\n implicit none\r\n real(dp), intent(in) :: x, y(:)\r\n real(dp), intent(out) :: dydx(:)\r\n end subroutine derivs\r\n end interface derivatives\r\n\r\n ! Calculate h^2.\r\n h2 = h * h\r\n ! Save current values of y.\r\n ys = yf\r\n call derivs(x, yf, dydx)\r\n ! Calculate the next step.\r\n yf = 2. * yf - yi + dydx * h2\r\n yi = ys\r\n end subroutine basic_verlet\r\n\r\n subroutine velocity_verlet(derivs,x,yi,yf,h)\r\n !==================================================!\r\n ! Velocity Verlet Integrator (2nd order equations) !\r\n ! Daniel Celis Garza 2nd Feb. 2016 !\r\n !--------------------------------------------------!\r\n ! f(x,y,dy) = ODEs to be solved !\r\n ! Let n := size(y), then y(1:n/2) := velocities !\r\n ! and y(n/2+1:n) := accelerations !\r\n !--------------------------------------------------!\r\n ! Inputs: !\r\n ! derivs = derivatives !\r\n ! h = step size !\r\n ! x = independent variable !\r\n ! yi() = array of dependent variables @ step i !\r\n !--------------------------------------------------!\r\n ! Outputs: !\r\n ! yf() = array of dependent variables @ step i+1 !\r\n !--------------------------------------------------!\r\n ! Locals: !\r\n ! dxdy() = array of derivatives !\r\n !==================================================!\r\n implicit none\r\n real(dp), intent(in) :: x, h, yi(:)\r\n real(dp), intent(out) :: yf(:)\r\n integer :: n_coords, n_derivs\r\n real(dp), dimension(size(yi)/2) :: dydx, dydxs\r\n real(dp) :: h2\r\n interface derivatives\r\n subroutine derivs(x,y,dydx)\r\n use nrtype\r\n implicit none\r\n real(dp), intent(in) :: x, y(:)\r\n real(dp), intent(out) :: dydx(:)\r\n end subroutine derivs\r\n end interface derivatives\r\n\r\n n_coords = size(yi) / 2\r\n n_derivs = size(yi)\r\n h2 = h*h\r\n\r\n ! Calculating a(t) from -\\nabla V(x(t+dt)) = F = m*a.\r\n call derivs(x, yi, dydx)\r\n\r\n ! Save the acceleration for the current step.\r\n dydxs = dydx\r\n\r\n ! Calculating x(t+dt)\r\n ! x(t+dt) = x(t) + v(t)*dt + 0.5*a(t)*dt^2\r\n yf(1: n_coords) = yi(1: n_coords) + yi(n_coords + 1: n_derivs) * h + 0.5_dp * dydx * h2\r\n\r\n ! Calculating a(t+dt) from -\\nabla V(x(t+dt)) = F = m*a.\r\n call derivs(x, yf, dydx)\r\n\r\n ! Calculating v(t+dt)\r\n ! v(t+dt) = v(t) + 0.5*(a(t) + a(t+dt))*dt\r\n yf(n_coords + 1: n_derivs) = yi(n_coords + 1 : n_derivs) + 0.5_dp * (dydxs + dydx) * h\r\n\r\n end subroutine velocity_verlet\r\nend module ode\r\n", "meta": {"hexsha": "b3c3fcf3cd592188c2e1bc1d12b638bbc4f81b7b", "size": 16165, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "ode/ode.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/ode.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/ode.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": 45.7932011331, "max_line_length": 92, "alphanum_fraction": 0.3810702134, "num_tokens": 4196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.8740772384450968, "lm_q1q2_score": 0.8326233621872018}} {"text": "PROGRAM F010\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: N = 2E+6\n INTEGER :: I, J\n INTEGER (KIND=8) :: PRIMES_SUM\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 PRIMES_SUM = 0\n DO I = 2, N\n IF (INTEGERS_LIST(I)) THEN\n PRIMES_SUM = PRIMES_SUM + I\n END IF\n END DO\n\n PRINT ('(I0)'), PRIMES_SUM\n\nEND PROGRAM F010\n", "meta": {"hexsha": "6ccead29673b181f0add062967f8d71e1336318d", "size": 729, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/010/010.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/010/010.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/010/010.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.8285714286, "max_line_length": 48, "alphanum_fraction": 0.5089163237, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214511730025, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.8325870468708433}} {"text": "! Explanation of constants and variables used in this program:\n! DARTS = number of throws at dartboard\n! ROUNDS = number of times \"DARTS\" is iterated\n! pi = average of pi for this iteration\n! avepi = average pi value for all iterations\n!\nprogram pi_calc\n\n integer, parameter :: DARTS = 100000\n integer, parameter :: ROUNDS = 10000\n double precision, parameter :: realpi=3.1415926535897\n real :: seednum\n double precision :: pi, avepi\n\n print *, 'Starting serial version of pi calculation...'\n\n avepi = 0\n do i = 1, ROUNDS\n pi = dboard(DARTS)\n avepi = ((avepi*(i-1)) + pi)/ i\n write(*,32) DARTS*i, avepi\n end do\n\n print *, ' '\n print *,'Error:', abs(avepi-realpi)/realpi\n print *, ' '\n\n32 format(' After',i8,' throws, average value of pi = ', &\n & f10.8,$)\n\ncontains\n\n ! Explanation of constants and variables used in this function:\n ! darts = number of throws at dartboard\n ! score = number of darts that hit circle\n ! n = index variable\n ! r = random number between 0 and 1\n ! x_coord = x coordinate, between -1 and 1\n ! x_sqr = square of x coordinate\n ! y_coord = y coordinate, between -1 and 1\n ! y_sqr = square of y coordinate\n ! pi = computed value of pi\n\n real function dboard(darts)\n\n integer :: darts, score, n\n real :: r\n double precision :: x_coord, x_sqr, y_coord, y_sqr, pi\n\n score = 0\n\n ! Throw darts at board. Done by generating random numbers\n ! between 0 and 1 and converting them to values for x and y\n ! coordinates and then testing to see if they \"land\" in\n ! the circle.\" If so, score is incremented. After throwing the\n ! specified number of darts, pi is calculated. The computed value\n ! of pi is returned as the value of this function, dboard.\n ! Note: the seed value for rand() is set in pi_calc.\n\n ! Note: Requires Fortran90 compiler due to random_number() function\n print *, ' '\n do 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 end do\n pi = 4.0 * score / darts\n dboard = pi\n end function dboard\n\nend program pi_calc\n", "meta": {"hexsha": "488e6aae2409f1c57667661d8c61f77f6c9d2033", "size": 2462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hw5/ser_pi_calc.f90", "max_stars_repo_name": "eusojk/cmse822-fs20-work", "max_stars_repo_head_hexsha": "bc27aa56c8ded7a81379cf173ba8988b961c38ee", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-14T16:31:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T16:31:52.000Z", "max_issues_repo_path": "hw5/ser_pi_calc.f90", "max_issues_repo_name": "cmse822/cmse822-fs20-work", "max_issues_repo_head_hexsha": "9f423b875e95adc0dc3804eec0d12ea3234dfbe2", "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": "hw5/ser_pi_calc.f90", "max_forks_repo_name": "cmse822/cmse822-fs20-work", "max_forks_repo_head_hexsha": "9f423b875e95adc0dc3804eec0d12ea3234dfbe2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-06T15:24:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-17T04:33:43.000Z", "avg_line_length": 30.775, "max_line_length": 74, "alphanum_fraction": 0.5970755483, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.8976952859490985, "lm_q1q2_score": 0.8324896642706539}} {"text": "FUNCTION determinant(jac)RESULT(det)\n!\n! This function returns the determinant of a 1x1, 2x2 or 3x3\n! Jacobian matrix.\n!\n IMPLICIT NONE \n !SELECTED_REAL_KIND: https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gfortran/SELECTED_005fREAL_005fKIND.html#SELECTED_005fREAL_005fKIND\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::jac(:,:)\n REAL(iwp)::det\n INTEGER::it \n it=UBOUND(jac,1) \n SELECT CASE(it)\n CASE(1)\n det=1.0_iwp\n CASE(2)\n det=jac(1,1)*jac(2,2)-jac(1,2)*jac(2,1)\n CASE(3)\n!rank = 3\n det=jac(1,1)*(jac(2,2)*jac(3,3)-jac(3,2)*jac(2,3))\n det=det-jac(1,2)*(jac(2,1)*jac(3,3)-jac(3,1)*jac(2,3))\n det=det+jac(1,3)*(jac(2,1)*jac(3,2)-jac(3,1)*jac(2,2))\n CASE DEFAULT\n WRITE(*,*)' wrong dimension for Jacobian matrix'\n END SELECT\nRETURN\nEND FUNCTION determinant\n", "meta": {"hexsha": "1787095b52266eead9cf95ba4f8a5917d9b6d039", "size": 792, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/determinant.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/determinant.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/determinant.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": 28.2857142857, "max_line_length": 130, "alphanum_fraction": 0.6843434343, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9748211546419276, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.8324122157958477}} {"text": "REAL FUNCTION sinc(x)\nIMPLICIT NONE\n REAL, INTENT(IN) :: x\n REAL, PARAMETER :: EPSILON = 1.0E-30\n IF (ABS(x) > EPSILON) THEN\n sinc = SIN(x) / x\n ELSE\n sinc = 1\n END IF\nEND FUNCTION sinc\n\nPROGRAM test_sinc\nIMPLICIT NONE\n REAL :: x, sinc\n INTEGER :: i, num_results, offset, adj\n\n WRITE(*, *) \"We will calculate sinc over a range of positive and negative values.\"\n WRITE(*, *) \"How many results would you like to see?\"\n READ(*, *) num_results\n\n offset = num_results / 2\n IF (MOD(num_results, 2) .eq. 0) THEN\n adj = 0\n ELSE\n adj = 1\n END IF\n\n DO i = 1, num_results\n WRITE(*, '(F9.6)') sinc(REAL(i - adj - offset))\n END DO\n !WRITE(*, 100) \"sinc(\", x, \") = \", sinc(x)\n !100 FORMAT (A, F12.6, A, F12.6)\nEND PROGRAM test_sinc\n", "meta": {"hexsha": "52b35944c48299d3cebbb93aafe9f5a3b038c7c8", "size": 751, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/test_sinc.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/test_sinc.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/test_sinc.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": 22.0882352941, "max_line_length": 84, "alphanum_fraction": 0.6125166445, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.9005297861178929, "lm_q1q2_score": 0.8322172392509399}} {"text": "module factorial_module\n implicit none\n\n contains\n recursive integer function factorial(i) result(answer)\n implicit none\n\n integer, intent(in) :: i\n\n if (i==0) then\n answer = 1\n else\n answer = i*factorial(i-1)\n end if\n end function\nend module\n\nprogram ch1208\n ! Recursive Factorial Evaluation\n use factorial_module\n implicit none\n\n integer :: i, f\n\n print *, 'type in the number, integer only'\n read *, i\n do while (i<0)\n print *, 'positive integer respected: re-input'\n read *, i\n end do\n f = factorial(i)\n print *, 'answer is ', f\nend program\n", "meta": {"hexsha": "2394b8dbe8afabbdcba8736c24f64774f14590d3", "size": 658, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch12/ch1208.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/ch1208.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/ch1208.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": 19.3529411765, "max_line_length": 58, "alphanum_fraction": 0.585106383, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.8321974112111996}} {"text": "MODULE precision\n ! dp = double precision\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\nPROGRAM Secant_Method\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: x1, x2, x3, f1, f2, f3, error, root\n WRITE(*, *) \"Enter value of 2 initial point \"\n ! For this question enter 2 initial point x1 and x2\n READ(*, *) x1, x2\n \n error = 1e-6\n f1 = Functn(x1)\n f2 = Functn(x2)\n\n DO\n x3 = (f2*x1 - f1*x2) / (f2 - f1)\n f3 = Functn(x3)\n IF (f3 .EQ. 0.0) THEN\n root = x3\n WRITE(*, *) \"Root is: \", root\n RETURN\n ENDIF\n\n IF (abs((x3 - x2)/x3) .LT. error) THEN \n root = x3\n WRITE(*, *) \"Root is: \", root\n RETURN\n ELSE \n x1 = x2\n f1 = f2\n x2 = x3\n f2 = f3\n ENDIF\n ENDDO \n\n CONTAINS\n REAL(KIND = dp) FUNCTION Functn(x)\n USE precision\n IMPLICIT NONE \n REAL(KIND = dp):: x, rho\n rho = 4.0_dp\n Functn = x*tan(x) - sqrt(rho**2 - x ** 2)\n RETURN \n END FUNCTION Functn\n\nEND PROGRAM Secant_Method\n", "meta": {"hexsha": "efab85409b6214c41b47dc8fa518fc37b7fc7c24", "size": 1147, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6. HA6 - Root Finding Method/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": "6. HA6 - Root Finding Method/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": "6. HA6 - Root Finding Method/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": 22.4901960784, "max_line_length": 57, "alphanum_fraction": 0.491717524, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.83200198165381}} {"text": "!\\file mbd_helper_dev.f90\n!\\author M. Sadhukhan\nmodule mbd_helper_dev\n\nuse mbd_interface, only: pi\n\ncontains\n\nrecursive function legendre(n, x)result(res)\n! Provides P_n(x)\nimplicit none\ninteger, intent(in):: n\ndouble precision, intent(in) :: x\ndouble precision :: res\ninteger :: i\n\nif (n == 0) then\n res = 1.d0\nelse if (n == 1) then\n res = x\nelse\n res = ((2.d0*n-1.d0)*x*legendre(n-1, x)-(n-1)*legendre(n-2, x))/(n*1.d0)\nend if\n!\nend function legendre\n! \nrecursive function derivlegendre(n, x)result(res)\n! Provides first derivative of P_n(x) wrt x\nimplicit none\ninteger, intent(in):: n\ndouble precision, intent(in) :: x\ndouble precision :: res\ninteger :: i\n\nif (n == 0) then\nres = 0.d0\nelse if (n == 1) then\nres = 1.d0\nelse\nres = ((2.d0*n-1.d0)*legendre(n-1, x)+ (2.d0*n-1.d0)*x*derivlegendre(n-1, x)-(n-1)*derivlegendre(n-2, x))/(n*1.d0)\nend if\n!\nend function derivlegendre\n!\nsubroutine gl_points(n, x, w)\nimplicit none\n! provides Gauss-Legendre abcissa and weights\ninteger, parameter :: m = 10\ninteger, intent(in) :: n\ndouble precision, dimension(n), intent(out) :: x, w\ninteger :: i\ndo i = 1, n\n x(i) = root_Legendre(n, i)\n w(i) = 2.d0/((1.d0-x(i)**2)*(derivlegendre(n,x(i)))**2)\nend do\nend subroutine gl_points\n!\nfunction root_Legendre(n, k)result(res)\n! provides the kth root for P_n(n)\nimplicit none\ndouble precision, parameter :: lim_err=1.d-12\ninteger, intent(in) :: n, k\ndouble precision :: err, res,root_guess_l,root_guess_u, x\n\nerr = 1.d0\n! guess from A&S 22.16.6\nroot_guess_l= cos(pi*(2*k-1)/(2.d0*n+1))\nroot_guess_u= cos((pi*2*k)/(2.d0*n+1))\n! Newton-Raphson\nx =root_guess_u\n!print*, \"Guess\", x\ndo while (err >= dabs(lim_err))\n!print*, \"P = \",legendre(n, x),\"P' = \",derivlegendre(n, x)\nx = x - legendre(n, x)/derivlegendre(n, x)\n!Print*, \"err = \", abs(legendre(n, x))\nerr =abs(legendre(n, x))\nend do\n!\nres = x\nend function root_Legendre\ninteger recursive function factorial(n)result(res)\nimplicit none\ninteger :: n\n\nif (n == 0)then\n res = 1\nelse\n res= n*factorial(n-1)\nend if\nend function factorial\n\nsubroutine diag_double(vector, matrix)\n! provides matrix with the diagonal containing vector\n! suitable for double precision\nimplicit none\ninteger :: i\ndouble precision, dimension(:), intent(in) :: vector\ndouble precision, dimension(size(vector), size(vector)), intent(out):: matrix\nmatrix = 0.d0\n\ndo i = 1, size(vector)\n matrix(i,i) = vector(i)\nend do\nend subroutine diag_double\n!\nsubroutine det(A, dt)\n! provides determinant dt of matrix A\nimplicit none\ninteger :: n, info, i\ndouble precision, dimension(:, :) :: A\ndouble precision :: dt\ninteger, dimension(size(A, 1)) :: ipiv\ndt = 1.d0\nn = size(A, 1)\n!do i = 1, n\n!print*, A(i, :)\n!end do\ncall dgetrf(n, n, A, n, ipiv, info)\n\n!print*, \"ipiv :\", ipiv\n\nif (info == 0)then\n do i = 1, n\n if(ipiv(i) == i)then\n dt = dt*A(i, i)\n else\n dt = -dt*A(i, i)\n end if\n end do\nelse\n print*, \"dgertf did not exited sucessfully\"\n print*, \"info =\", info\n stop\nend if\n!print*, \"dt = \",dt\nend subroutine det\n!\nfunction i_matrix(n) result(matrix)\n! provides identity matrix of dimension n\nimplicit none\ninteger, intent(in) :: n\ndouble precision, dimension(n, n) :: matrix\ninteger :: i\ndouble precision, dimension(n) :: diag1\ndiag1 = 1.d0\ncall diag_double(diag1, matrix)\nend function i_matrix\n!\nfunction matrix_combine( n, matA, matB)result(matAB)\nimplicit none\n! combine two nxn matrices\ninteger, intent(in) :: n\ndouble precision, dimension(n, n), intent(in) :: matA, matB\ndouble precision, dimension(2*n, n) :: matAB\n\nmatAB(1:n, :) = matA\nmatAB(n+1:2*n, : ) = matB\nend function matrix_combine\n!\nfunction matrix_embed(n, matA, Bign, rpos, cpos)result(Bigmatrix)\nimplicit none\ninteger, intent(in) :: n, Bign, rpos, cpos\ndouble precision, dimension(n, n), intent(in) :: matA\ndouble precision, dimension(Bign, Bign) :: Bigmatrix\nif (rpos+n-1 > Bign .or. cpos+n-1 > Bign) then\n print*, \"Matrix sizes are not fit for embedding ... aborting execusion\"\n stop\nend if\nBigmatrix = 0.d0\nBigmatrix(rpos:, cpos:) =matA\n\nend function matrix_embed\n!\nfunction Matrix_invert(A)result(Ainv)\n! Provides matrix inversion of A\nimplicit none\ndouble precision, dimension(:,:), intent(in) :: A\ndouble precision, dimension(size(A, 1),size(A, 1)):: Ainv\n\ninteger :: n, info, i\ninteger, dimension(size(A,1)) :: ipiv\ndouble precision, dimension(size(A,1)**2) :: work\nipiv= 1\nwork = 0.d0\nn = size(A, 1)\nAinv = 0.d0\nif (n>1)then\ncall DGETRI(n, A, n, ipiv, work, n**2, info)\nif(info /=0)then\n print*, \"Matrix inversion failed ... Aborting, info =\", info\n stop\nend if\n Ainv= A\nelse if (n == 1)then\n Ainv= A\nend if\n\nend function Matrix_invert\n!\nfunction repeat(n, number)result(vector)\nimplicit none\ninteger, intent(in) :: n\ndouble precision,intent(in) :: number\ndouble precision, dimension(n) :: vector\nvector = number\nend function repeat\n!\nfunction combine_vector(nA, vA, nB, vB)result(vAB)\nimplicit none\ninteger, intent(in) :: nA, nB\ndouble precision, dimension(na), intent(in) :: vA\ndouble precision, dimension(nb), intent(in) :: vB\ndouble precision, dimension(na+nb) :: vAB\nvAB = 0.d0\nvAB(1:na) = vA\nvAB(na+1:nb+na) = vB\nend function combine_vector\n\n\nsubroutine printmat(A, message)\nimplicit none\ndouble precision, dimension(:, :), intent(in) :: A\ncharacter(len=*), optional :: message\ncharacter(len=20) :: fmt\ninteger :: i, n\n\nif(present(message))print*, message\nn = size(A, 1)\nwrite (fmt, *) n\nfmt = \"(1x,\"//trim(adjustl(fmt))//\"f8.4)\"\n!print*, fmt\n!stop\ndo i = 1, n\n write(*, trim(fmt)) A(i, :)\nend do\nend subroutine printmat\n\nend module\n", "meta": {"hexsha": "008d6e8549bf564acdca217fdca72347fe9e016a", "size": 5475, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mbd_helper_dev.f90", "max_stars_repo_name": "nickcafferry/Machine-Learning-in-the-Molecular-Sciences", "max_stars_repo_head_hexsha": "5a3573fe1ab16816f1872f8435e289693f4c03bd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-25T12:05:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-25T12:05:10.000Z", "max_issues_repo_path": "src/mbd_helper_dev.f90", "max_issues_repo_name": "nickcafferry/Machine-Learning-in-Molecular-Sciences", "max_issues_repo_head_hexsha": "5a3573fe1ab16816f1872f8435e289693f4c03bd", "max_issues_repo_licenses": ["MIT"], "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/mbd_helper_dev.f90", "max_forks_repo_name": "nickcafferry/Machine-Learning-in-Molecular-Sciences", "max_forks_repo_head_hexsha": "5a3573fe1ab16816f1872f8435e289693f4c03bd", "max_forks_repo_licenses": ["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.9079497908, "max_line_length": 114, "alphanum_fraction": 0.6876712329, "num_tokens": 1827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8807970811069351, "lm_q1q2_score": 0.8316282185702543}} {"text": "Module MathFuncMod\n\ncontains\nrecursive Function factorial(n) result(f)\n implicit none\n integer :: n\n integer (kind = 4) :: f\n if (n<0) then\n f=0\n else\n select case (n) \n case (0)\n f = 1\n case (1)\n f = 1\n case (2)\n f = 2\n case ( 3)\n f = 6\n case ( 4)\n f = 24\n case ( 5)\n f = 120\n case ( 6)\n f = 720\n case ( 7)\n f = 5040\n case ( 8)\n f = 40320\n case ( 9)\n f = 362880\n case ( 10)\n f = 3628800\n case ( 11)\n f = 39916800\n case ( 12)\n f = 479001600\n case default\n f = n*factorial(n-1)\n end select\n endif\nend function factorial\n\nrecursive Function doublefactorial(n) result(f)\n integer, intent(in):: n\n integer (kind = 4) :: f\n if (n<0) then\n f=0\n return\n else\n select case (n)\n case (0)\n f = 1\n case (1)\n f = 1\n case (2)\n f = 2\n case (3)\n f = 3\n case (4)\n f = 8\n case (5)\n f = 15\n case (6)\n f = 48\n case (7)\n f = 105\n case (8)\n f = 384\n case (9)\n f = 945\n case (10)\n f = 3840\n case (11)\n f = 10395\n case (12)\n f = 46080\n case (13)\n f = 135135\n case (14)\n f = 645120\n case (15)\n f = 2027025\n case (16)\n f = 10321920\n case (17)\n f = 34459425\n case (18)\n f = 185794560\n case default\n f = n*doublefactorial(n-2)\n end select\n endif\nend function doublefactorial\n\n\nrecursive Function binomial(n, m) result(f)\n implicit none\n integer :: n,m,ml\n integer (kind = 4) :: f\n if (n<=0 .or. m>n .or. m<0) then\n f = 0;\n return\n endif\n \n if (m>n/2) then\n ml=n-m;\n else \n ml=m;\n endif\n \n select case (ml)\n case (0)\n f = 1\n return\n case (1)\n f = n\n return\n case (2)\n f = n*(n-1)/2\n return\n case (3)\n f = n*(n-1)*(n-2)/6\n return\n end select\n\n if (n<=12) then\n f = factorial(n)/factorial(m)/factorial(n-m)\n else \n f = (n*binomial(n-1,ml-1)/ml)\n endif\n\nend function binomial\n\nEnd Module MathFuncMod\n", "meta": {"hexsha": "410cd01042b148a92c548b2d1815afee893e0aa3", "size": 2642, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "TPSA/mod_mathfunc.f90", "max_stars_repo_name": "zhicongliu/ImpactTPSA", "max_stars_repo_head_hexsha": "539a159fdb3e2c850cc492374c9a66eb21b55a54", "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": "TPSA/mod_mathfunc.f90", "max_issues_repo_name": "zhicongliu/ImpactTPSA", "max_issues_repo_head_hexsha": "539a159fdb3e2c850cc492374c9a66eb21b55a54", "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": "TPSA/mod_mathfunc.f90", "max_forks_repo_name": "zhicongliu/ImpactTPSA", "max_forks_repo_head_hexsha": "539a159fdb3e2c850cc492374c9a66eb21b55a54", "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": 19.4264705882, "max_line_length": 52, "alphanum_fraction": 0.3735806207, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693241982893258, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8314553806876865}} {"text": "program pascalsTriangle\n\n ! This program prints n number of lines in pascal's triangle. 'line' represents the line number of pascal's triangle, \n ! 'spaces' is the number of spaces that are required, k is the iterable number/ number of element in each line in triangle,\n ! and c is the actual coefficient/number to be printed.\n ! This program prints in a pretty triangle, if the triangle is skewed adjust line 17 and 14.\n\n implicit none\n integer:: n\n integer(kind =16) :: line, spaces, k, c\n write(*,*) \"Enter the number of rows of the Pascal Triangle: \"\n read (*,*) n\n do line = 0,n-1\n c = 1\n do spaces = 0,n-line-1 !write total n-lines (-1 is with experiment for adjusting) spaces before printing number\n write(*,'(a)',advance=\"no\") \" \"\n end do\n do k = 0,line\n write(*,'(i5,a)',advance=\"no\") c, \" \" ! i5 works best for me, otherwise i have to change the number of spaces in above loop\n c = c * (line-k)/(k+1) !c calculates the coefficient to write every step\n end do\n write(*,*) \" \" ! this is there to end the line finally and move to next line\n end do\nend program pascalsTriangle", "meta": {"hexsha": "4939318c2385e922b963a9510e0049a56805a5de", "size": 1238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pascaltri.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": "pascaltri.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": "pascaltri.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": 51.5833333333, "max_line_length": 137, "alphanum_fraction": 0.6171243942, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517050371972, "lm_q2_score": 0.8652240773641088, "lm_q1q2_score": 0.8314385523822762}} {"text": " program demo_epsilon\n use,intrinsic :: iso_fortran_env, only : dp=>real64,sp=>real32\n implicit none\n real(kind=sp) :: x = 3.143\n real(kind=dp) :: y = 2.33d0\n\n ! so if x is of type real32, epsilon(x) has the value 2**-23\n print *, epsilon(x)\n ! note just the type and kind of x matter, not the value\n print *, epsilon(huge(x))\n print *, epsilon(tiny(x))\n\n ! the value changes with the kind of the real value though\n print *, epsilon(y)\n\n ! adding and subtracting epsilon(x) changes x\n write(*,*)x == x + epsilon(x)\n write(*,*)x == x - epsilon(x)\n\n ! these next two comparisons will be .true. !\n write(*,*)x == x + epsilon(x) * 0.999999\n write(*,*)x == x - epsilon(x) * 0.999999\n\n ! you can calculate epsilon(1.0d0)\n write(*,*)my_dp_eps()\n\n contains\n\n function my_dp_eps()\n ! calculate the epsilon value of a machine the hard way\n real(kind=dp) :: t\n real(kind=dp) :: my_dp_eps\n\n ! starting with a value of 1, keep dividing the value\n ! by 2 until no change is detected. Note that with\n ! infinite precision this would be an infinite loop,\n ! but floating point values in Fortran have a defined\n ! and limited precision.\n my_dp_eps = 1.0d0\n SET_ST: do\n my_dp_eps = my_dp_eps/2.0d0\n t = 1.0d0 + my_dp_eps\n if (t <= 1.0d0) exit\n enddo SET_ST\n my_dp_eps = 2.0d0*my_dp_eps\n\n end function my_dp_eps\n\n end program demo_epsilon\n", "meta": {"hexsha": "f57f2ace4700c868f5136d1838d8b972d5575123", "size": 1527, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/epsilon.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/epsilon.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/epsilon.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": 30.54, "max_line_length": 67, "alphanum_fraction": 0.5933202358, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.9046505434556231, "lm_q1q2_score": 0.8309036559480482}} {"text": "module vector\nimplicit none\ncontains\n subroutine get_vec_cross(v1, v2, m, cross)\n\n integer,intent(in)::m\n real(kind=4),intent(in),dimension(m)::v1,v2\n real(kind=4),intent(out),dimension(m)::cross\n\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\n return\n\n end subroutine get_vec_cross\n\n subroutine get_vec_len(vec,vec_len,m)\n\n integer::i\n integer,intent(in)::m\n real(kind=4)::sum_value\n real(kind=4),intent(in),dimension(m)::vec\n real(kind=4),intent(out)::vec_len\n\n sum_value=0.0\n do i=1,m\n sum_value=sum_value+vec(i)**2\n end do\n vec_len = sqrt(sum_value)\n\n return\n\n end subroutine get_vec_len\n\n subroutine norm_vec(vec,new_vec,m)\n\n integer::i\n integer,intent(in)::m\n real(kind=4)::sum_value\n real(kind=4),intent(in),dimension(m)::vec\n real(kind=4),intent(out),dimension(m)::new_vec\n\n sum_value = 0.0\n do i=1,m\n sum_value=sum_value+vec(i)**2\n end do\n do i=1,m\n new_vec(i)=vec(i)/sqrt(sum_value)\n end do\n\n return\n\n end subroutine norm_vec\n\n subroutine project_vec(vec_1,vec_2,m,vec_1_proj_vec_2,sign_value)\n ! project vec_1 on the basis of vec_2\n\n integer,intent(in)::m\n real(kind=4)::a,b\n real(kind=4),intent(out)::sign_value\n real(kind=4),intent(in),dimension(m)::vec_1,vec_2\n real(kind=4),intent(out),dimension(m)::vec_1_proj_vec_2\n\n a=DOT_PRODUCT(vec_1,vec_2)\n b=DOT_PRODUCT(vec_2,vec_2)\n vec_1_proj_vec_2=a*vec_2/b\n\n if ( a<0.0 ) then\n sign_value=-1.0\n else\n sign_value=1.0\n end if\n \n return\n\n end subroutine project_vec\n\n subroutine center_of_mass(mass,data_array,data_center,n,m)\n\n integer::i,j\n integer,intent(in)::n,m\n real(kind=4)::sum_value\n real(kind=4)::sum_value_mass\n real(kind=4),intent(in),dimension(n)::mass\n real(kind=4),intent(in),dimension(n,m)::data_array\n real(kind=4),intent(out),dimension(m)::data_center\n\n sum_value_mass=0.0\n\n do i=1,n\n sum_value_mass=sum_value_mass+mass(i)\n end do\n\n do i=1,m\n sum_value=0.0\n do j=1,n\n sum_value=sum_value+mass(j)*data_array(j,i)\n end do\n data_center(i)=sum_value/sum_value_mass\n end do\n\n return\n\n end subroutine center_of_mass\n\nend module vector\n", "meta": {"hexsha": "8c11b075a65231caaa3eed2fe61e8aca6cdb7fa9", "size": 2287, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/vector.f90", "max_stars_repo_name": "JunboLu/CP2K_kit", "max_stars_repo_head_hexsha": "0950f37f253c3f90d6a0539c57f1be1045e7317d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-04-19T03:40:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T12:53:33.000Z", "max_issues_repo_path": "lib/vector.f90", "max_issues_repo_name": "JunboLu/CP2K_kit", "max_issues_repo_head_hexsha": "0950f37f253c3f90d6a0539c57f1be1045e7317d", "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": "lib/vector.f90", "max_forks_repo_name": "JunboLu/CP2K_kit", "max_forks_repo_head_hexsha": "0950f37f253c3f90d6a0539c57f1be1045e7317d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-28T02:55:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-21T12:54:52.000Z", "avg_line_length": 21.1759259259, "max_line_length": 67, "alphanum_fraction": 0.6523830345, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.8308321435925068}} {"text": "MODULE m_statist\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! MODULE: m_statist.f03\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Module for computing of representative statistical quantities of a data series \r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\t13 October 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\n\r\n\r\nSUBROUTINE statist (dx, RMSdx, Sigmadx, MEANdx, MINdx, MAXdx)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: statist.f03\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Compute the statistical quantities (RMS, Min, Max) of a series matrix of numerical differences \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - dx:\t\t\tMatrix with the x series differences (dynamic allocatable array) \r\n!\r\n! Output arguments:\r\n! - RMSdx: \t\tRoot Mean Square of dx \r\n! - Sigmadx: \tStandard Deviation of dx\r\n! - MEANdx: \tMean value of dx\r\n! - MINdx: \t\tMinimum value of dx\r\n! - MAXdx: \t\tMaximum value of dx\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\t13 October 2017\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n IMPLICIT NONE\r\n\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_d), INTENT(IN), ALLOCATABLE, DIMENSION(:) :: dx\r\n! ----------------------------------------------------------------------\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: RMSdx, Sigmadx, MEANdx, MINdx, MAXdx \r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_d) :: sum_dx, sum_dx2, sum_dxx \r\n INTEGER (KIND = prec_int8) :: sz1, sz2, size_dx, i \r\n INTEGER (KIND = prec_int2) :: AllocateStatus, DeAllocateStatus\r\n! ----------------------------------------------------------------------\t\r\n\r\n\r\nsz1 = size(dx, DIM = 1)\r\n!sz2 = size(dx, DIM = 2)\r\n\r\n\r\nsize_dx = sz1\r\nsum_dx = 0.0D0\r\nsum_dx2 = 0.0D0\r\nMINdx = dx(1)\r\nMAXdx = dx(1)\r\nDo i = 1 , size_dx\r\n sum_dx2 = sum_dx2 + dx(i)**2\r\n sum_dx = sum_dx + dx(i)\r\n If (dx(i) < MINdx) Then\r\n MINdx = dx(i)\r\n End IF\r\n If (dx(i) > MAXdx) Then\r\n MAXdx = dx(i)\r\n End IF\r\n \r\nEnd Do\r\n\r\n\r\n! RMS\r\nRMSdx = sqrt(sum_dx2 / size_dx)\r\n\r\n! Mean\r\nMEANdx = sum_dx / size_dx\r\n\r\n! Standard Deviation\r\nsum_dxx = 0.0D0\r\nDO i = 1 , size_dx\t \r\n sum_dxx = sum_dxx + (dx(i) - MEANdx)**2\r\nEND DO\r\nSigmadx = sqrt(sum_dxx / size_dx)\t \r\nSigmadx = sqrt(sum_dxx / (size_dx - 1) )\t \r\n\r\n\r\n\r\nEND SUBROUTINE\r\n\r\n\r\n\r\n\r\nEnd Module\r\n\r\n", "meta": {"hexsha": "122a15e81dda2b607b12c4f9923854e37057c0ce", "size": 3323, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/m_statist.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_statist.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_statist.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": 28.6465517241, "max_line_length": 99, "alphanum_fraction": 0.4074631357, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8306763597054379}} {"text": "SUBROUTINE linint (x1, y1, x2, y2, x3, y3, x4, y4, xc, yc, &\r\n & intersect, coincide)\r\n\r\n ! m o d u l e s\r\n\r\n USE kind_param, ONLY: double\r\n IMPLICIT NONE\r\n\r\n ! d u m m y a r g u m e n t s\r\n\r\n REAL (double) :: x1\r\n REAL (double) :: y1\r\n REAL (double) :: x2\r\n REAL (double) :: y2\r\n REAL (double) :: x3\r\n REAL (double) :: y3\r\n REAL (double) :: x4\r\n REAL (double) :: y4\r\n REAL (double) :: xc\r\n REAL (double) :: yc\r\n LOGICAL, INTENT (OUT) :: intersect\r\n LOGICAL, INTENT (OUT) :: coincide\r\n\r\n ! i n t e r f a c e b l o c k s\r\n\r\n INTERFACE\r\n INCLUDE 'linequ.h'\r\n INCLUDE 'insidf.h'\r\n END INTERFACE\r\n\r\n !-----------------------------------------------\r\n ! l o c a l v a r i a b l e s\r\n\r\n REAL (double) :: w, a1, b1, c1, a2, b2, c2, wx, wy\r\n LOGICAL :: between1, between2\r\n !-----------------------------------------------\r\n\r\n intersect = .FALSE.\r\n coincide = .FALSE.\r\n\r\n ! equation of the 1st line: a1*x + b1*y = c1\r\n ! 2nd line: a2*x + b2*y = c2\r\n\r\n IF (x1 == x2 .AND. y1 == y2) RETURN ! line is reduced to a point\r\n\r\n CALL linequ (x1, y1, x2, y2, a1, b1, c1)\r\n CALL linequ (x3, y3, x4, y4, a2, b2, c2)\r\n\r\n ! solution of the set of the two equations\r\n ! a1*x + b1*y = c1\r\n ! a2*x + b2*y = c2\r\n !\r\n ! w, wx, wy - determinants\r\n \r\n w = a1 * b2 - a2 * b1\r\n wx = c1 * b2 - c2 * b1\r\n wy = a1 * c2 - a2 * c1\r\n\r\n IF (w /= 0.) THEN ! not parallel\r\n\r\n wy = a1 * c2 - a2 * c1\r\n xc = wx / w\r\n yc = wy / w\r\n CALL insidf (x1, y1, x2, y2, xc, yc, between1)\r\n CALL insidf (x3, y3, x4, y4, xc, yc, between2)\r\n IF (between1 .AND. between2) intersect = .TRUE.\r\n\r\n ELSE IF (w == 0 .AND. wx == 0 .AND. wy == 0) THEN !coinciding\r\n\r\n coincide = .TRUE.\r\n\r\n END IF\r\n\r\n RETURN\r\n\r\nEND SUBROUTINE linint\r\n", "meta": {"hexsha": "9c8351eb272036634a8798925713732eb94d5a66", "size": 1822, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/drawb/linint.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/drawb/linint.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/drawb/linint.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": 23.6623376623, "max_line_length": 67, "alphanum_fraction": 0.4763995609, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122756889437, "lm_q2_score": 0.8670357666736773, "lm_q1q2_score": 0.8305442043580902}} {"text": "! Program to compute the second derivative of exp(x). \n! Three calling functions are included\n! in this version. In one function we read in the data from screen,\n! the next function computes the second derivative\n! while the last function prints out data to screen.\n\n! The variable h is the step size. We also fix the total number\n! of divisions by 2 of h. The total number of steps is read from\n! screen \n\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\n! Here you can include specific functions which can be used by\n! many subroutines or functions\n\nMODULE functions\nUSE constants\nIMPLICIT NONE\nCONTAINS\n SUBROUTINE derivative(number_of_steps, x, initial_step, h_step, &\n computed_derivative)\n USE constants\n INTEGER, INTENT(IN) :: number_of_steps\n INTEGER :: loop\n REAL(DP), DIMENSION(number_of_steps), INTENT(INOUT) :: &\n computed_derivative, h_step\n REAL(DP), INTENT(IN) :: initial_step, x \n REAL(DP) :: h\n ! calculate the step size \n ! initialise the derivative, y and x (in minutes) \n ! and iteration counter \n h = initial_step\n ! start computing for different step sizes \n DO loop=1, number_of_steps\n ! setup arrays with derivatives and step sizes\n h_step(loop) = h\n computed_derivative(loop) = (EXP(x+h)-2.*EXP(x)+EXP(x-h))/(h*h)\n h = h*0.5\n ENDDO\n END SUBROUTINE derivative\n\nEND MODULE functions\n\nPROGRAM second_derivative\n USE constants\n USE functions\n IMPLICIT NONE\n ! declarations of variables \n INTEGER :: number_of_steps, loop\n REAL(DP) :: x, initial_step\n REAL(DP), ALLOCATABLE, DIMENSION(:) :: h_step, computed_derivative\n ! read in input data from screen \n WRITE(*,*) 'Read in initial step, x value and number of steps'\n READ(*,*) initial_step, x, number_of_steps\n ! open file to write results on\n OPEN(UNIT=7,FILE='out.dat')\n ! allocate space in memory for the one-dimensional arrays \n ! h_step and computed_derivative \n ALLOCATE(h_step(number_of_steps),computed_derivative(number_of_steps))\n ! compute the second derivative of exp(x)\n h_step = 0.0_dp; computed_derivative = 0.0_dp \n CALL derivative(number_of_steps,x,initial_step,h_step,computed_derivative)\n\n ! Then we print the results to file \n DO loop=1, number_of_steps\n WRITE(7,'(E16.10,2X,E16.10)') LOG10(h_step(loop)),&\n LOG10 ( ABS ( (computed_derivative(loop)-EXP(x))/EXP(x)))\n ! free memory\n ENDDO\n DEALLOCATE( h_step, computed_derivative) \nEND PROGRAM second_derivative\n\n\n", "meta": {"hexsha": "d0420cd007be9cc7d20370c360f5f0fae0ad55fa", "size": 2789, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/Classes/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/Classes/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/Classes/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": 34.4320987654, "max_line_length": 77, "alphanum_fraction": 0.6977411259, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760996, "lm_q2_score": 0.8933094067644466, "lm_q1q2_score": 0.8302778609906608}} {"text": "program cal_derteminant\n implicit none\n\n integer :: i,j,io \n integer :: m,n\n real, dimension(:,:), allocatable :: matrix\n real :: determinan,caldet\n\n ! Read number of data\n write(*,*) 'Status IOSTAT'\n open(1, file='data_matrix_high_A.txt')\n m = 0\n do\n read(1,*,iostat=io)\n write(*,*)'Baris ke-',m+1, io\n if (io /= 0) exit\n m = m + 1\n end do\n close(1)\n\n ! Set number of rows and columns of square matrix\n m = int(m**0.5)\n n = m\n\n ! Allocate memory size for array variable\n allocate(matrix(m,n))\n\n ! Read matrix file\n open(2,file='data_matrix_high_A.txt')\n do i = 1,m \n do j = 1,n\n read(2,*) matrix(i,j)\n end do\n end do\n close(2)\n\n ! Show matrix\n write(*,*) \n write(*,*) 'Matrix'\n do i = 1,m\n write(*,*) (matrix(i,j), j=1,n)\n end do\n\n write(*,*) \n\n ! Calculate determinant by calling its function\n determinan = caldet(matrix,m,n)\n\n write(*,*) 'Determinan:'\n write(*,*) determinan\n\n deallocate(matrix)\nend program\n\nsubroutine getsubmatrix(matrix,m,n,mainrow,maincolumn,submatrix)\n ! ------------------------------------------------------------------\n ! This is a subroutine to get a cofactor/submatrix from main matrix\n ! This concept algorithm is obtained from\n ! https://www.geeksforgeeks.org/adjoint-inverse-matrix/ in C++\n ! ------------------------------------------------------------------\n real, dimension(m,n) :: matrix ! input matrix\n real, dimension(m-1,n-1) :: submatrix ! output matrix\n integer :: maincolumn, mainrow, row, col\n\n i = 1\n j = 1\n do row = 1,m \n do col = 1,n\n if ((row .ne. mainrow) .and. (col .ne. maincolumn)) then \n submatrix(i,j) = matrix(row,col)\n if (j == n-1) then \n j = 1\n i = i + 1\n else\n j = j + 1\n end if\n end if\n end do\n end do\n \nend subroutine getsubmatrix\n\nrecursive function caldet(matrix,m,n) result(sumdet)\n ! ------------------------------------------------------------------\n ! This is a recursive function to calculate determinant.\n ! ------------------------------------------------------------------\n real, dimension(m,n) :: matrix\n real, dimension(m-1,n-1) :: submatrix\n integer :: j\n\n if (m == 2 .and. n == 2 ) then\n det = matrix(1,1)*matrix(2,2) - matrix(1,2)*matrix(2,1)\n else\n det = 0\n do j = 1,n\n sign = (-1)**(j-1)\n call getsubmatrix(matrix,m,n,1,j,submatrix)\n det = det + (sign * matrix(1,j) * caldet(submatrix,m-1,n-1))\n end do\n end if\n\n sumdet = det\n return\nend function caldet", "meta": {"hexsha": "fc61f66178f7aee25db27275a44b91d59b34b702", "size": 2796, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "determinant_high.f95", "max_stars_repo_name": "auliakhalqillah/AlgortimaDasar", "max_stars_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "determinant_high.f95", "max_issues_repo_name": "auliakhalqillah/AlgortimaDasar", "max_issues_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "determinant_high.f95", "max_forks_repo_name": "auliakhalqillah/AlgortimaDasar", "max_forks_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_forks_repo_licenses": ["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.8846153846, "max_line_length": 89, "alphanum_fraction": 0.4796137339, "num_tokens": 766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.900529795461386, "lm_q1q2_score": 0.8302180813734029}} {"text": "C NUMERICAL METHODS: FORTRAN Programs, (c) John H. Mathews 1994\nC To accompany the text:\nC NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992\nC Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.\nC This free software is complements of the author.\nC\nC Algorithm 7.2 (Composite Simpson Rule). \nC Section 7.2, Composite Trapezoidal and Simpson's Rule, Page 365\nC\n\nC comment added by Kongbin Kang\nC F: integrand function\nC A: lower integration limit\nC B: higher integration limit\nC M: number of intervals. Notice, the subintervals used is 2M\nC Srule: output parameter to store simpson rule result\n \n SUBROUTINE SIMPRU(F,A,B,M,Srule)\n INTEGER K,M\n DOUBLE PRECISION A,B,H,Sum,SumEven,SumOdd,Srule,X\n EXTERNAL F\n H=(B-A)/(2*M)\n SumEven=0\n DO K=1,(M-1)\n X=A+H*2*K\n SumEven=SumEven+F(X)\n ENDDO\n SumOdd=0\n DO K=1,M\n X=A+H*(2*K-1)\n SumOdd=SumOdd+F(X)\n ENDDO\n Sum=H*(F(A)+F(B)+2*SumEven+4*SumOdd)/3\n Srule=Sum\n RETURN\n END\n\n SUBROUTINE XSIMPRU(F,A,B,M,Srule)\nC This subroutine uses labeled DO loop(s).\n INTEGER K,M\n DOUBLE PRECISION A,B,H,Sum,SumEven,SumOdd,Srule,X\n EXTERNAL F\n H=(B-A)/(2*M)\n SumEven=0\n DO 10 K=1,(M-1)\n X=A+H*2*K\n SumEven=SumEven+F(X)\n10 CONTINUE\n SumOdd=0\n DO 20 K=1,M\n X=A+H*(2*K-1)\n SumOdd=SumOdd+F(X)\n20 CONTINUE\n Sum=H*(F(A)+F(B)+2*SumEven+4*SumOdd)/3\n Srule=Sum\n RETURN\n END\n\n\n", "meta": {"hexsha": "a7cdcd73484693a8428901b5f40e701bfb43505c", "size": 1582, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/simpson.f", "max_stars_repo_name": "eile/ITK", "max_stars_repo_head_hexsha": "2f09e6e2f9e0a4a7269ac83c597f97b04f915dc1", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-05-22T03:47:43.000Z", "max_stars_repo_stars_event_max_datetime": "2016-06-16T20:57:21.000Z", "max_issues_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/simpson.f", "max_issues_repo_name": "GEHC-Surgery/ITK", "max_issues_repo_head_hexsha": "f5df62749e56c9036e5888cfed904032ba5fdfb7", "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/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/simpson.f", "max_forks_repo_name": "GEHC-Surgery/ITK", "max_forks_repo_head_hexsha": "f5df62749e56c9036e5888cfed904032ba5fdfb7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-06-23T16:03:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T09:25:08.000Z", "avg_line_length": 26.3666666667, "max_line_length": 78, "alphanum_fraction": 0.597977244, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.9005297834483234, "lm_q1q2_score": 0.8302180645027681}} {"text": "SUBROUTINE 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\n! End of mainloop 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.\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 gauss_jordan\nIMPLICIT NONE\nINTEGER, PARAMETER :: MAX_SIZE = 10\nREAL, DIMENSION(MAX_SIZE, MAX_SIZE) :: a\nREAL, DIMENSION(MAX_SIZE) :: b\nINTEGER :: error\nCHARACTER(len=20) :: file_name\nINTEGER :: i, j, n, istat\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\n ! If the number of equations is <= MAX_SIZE, read them in\n ! and process them.\n size_ok: IF (n <= MAX_SIZE) THEN\n DO i = 1, n\n READ(1, *) (a(i, j), j = 1, n), b(i)\n END DO\n\n ! Display coefficients.\n WRITE(*, \"(/,'Coefficients before call:')\")\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, MAX_SIZE, n, 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, 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, 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\nEND PROGRAM gauss_jordan\n", "meta": {"hexsha": "6c91005af5a3912c5b936d983664c11205c92f92", "size": 3617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap9/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/chap9/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/chap9/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": 27.8230769231, "max_line_length": 66, "alphanum_fraction": 0.6112800664, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.899121386730912, "lm_q1q2_score": 0.8299242572229789}} {"text": "!-------------------------------------------------------\n!\n! main.f90\n!\n! Description:\n! ------------\n! Fortran snippet to produce a grid of real\n! numbers with logarithmically equal spacing.\n!\n! Record of Revisions:\n! --------------------\n!\n! Date: Author: Description:\n! ----- ------- ------------\n! 2020-03-06 P. Stegmann Original Code\n!\n!\n!\n!\n! Copyright © 2020 Patrick Stegmann\n!\n! This file is part of ScatteringBase.\n!\n! ScatteringBase is free software:\n! you can redistribute it and/or modify it under \n! the terms of the Apache License as published by\n! the Apache Software Foundation, either version 2.0\n! of the License, or (at your option) any later version.\n!\n! This program is distributed in the hope that it will \n! be useful,\n! but WITHOUT ANY WARRANTY; without even the implied \n! warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \n! PURPOSE. See the Apache License for more details.\n!\n! You should have received a copy of the Apache 2.0 \n! License along with this program. If not, \n! see .\n!\n!-------------------------------------------------------\n\n\nPROGRAM MAIN\n\n\tIMPLICIT NONE\n\t! Data Dictionary:\n\tREAL(KIND=8), PARAMETER :: start = 0.1\n\tREAL(KIND=8), PARAMETER :: fin = 3000.\n\tINTEGER(KIND=4), PARAMETER :: steps = 100\n\tREAL(KIND=8),DIMENSION(steps) :: grid\n INTEGER(KIND=4), PARAMETER :: FileUnit = 444\n\n\t! Instructions:\n\n\t! Compute the logequal grid:\n\tgrid = LOGEQUAL(start,fin,steps)\n\n\t! Output grid to file:\n\tOPEN(UNIT=FileUnit, &\n\t\t FILE=\"grid.txt\", &\n\t\t ACTION=\"WRITE\", &\n\t\t STATUS=\"REPLACE\")\n\tWRITE(FileUnit,*) grid\n\tCLOSE(FileUnit)\n\nCONTAINS\n\n\tPURE FUNCTION LOGEQUAL(start,fin,steps) RESULT(grid)\n\t\t! Data Dictionary\n\t\tREAL(KIND=8), INTENT(IN) :: start\n\t\tREAL(KIND=8), INTENT(IN) :: fin\n\t\tINTEGER(KIND=4), INTENT(IN) :: steps\n\t\tREAL(KIND=8),DIMENSION(steps) :: grid\n\t\tINTEGER(KIND=4) :: ii\n\t\tREAL(KIND=8) :: tmp\n\t\t! Function Instructions:\n\t\ttmp = LOG(start)\n\t\tgrid_loop: DO ii = 1, steps\n\t\t\ttmp = (LOG(fin)-LOG(start))/steps + tmp\n\t\t\tgrid(ii) = EXP(tmp) \n\t\tEND DO grid_loop\n\t\tRETURN\n\tEND FUNCTION LOGEQUAL\n\nEND PROGRAM MAIN\n", "meta": {"hexsha": "384c6c60afb5af490f4e16ef1c635f527811d2ba", "size": 2157, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SizeGrid/main.f90", "max_stars_repo_name": "StegmannJCSDA/ScatteringBase", "max_stars_repo_head_hexsha": "dd7412c08061e2415a2dd2702d4497e6a3cb01aa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-16T17:39:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T07:20:43.000Z", "max_issues_repo_path": "SizeGrid/main.f90", "max_issues_repo_name": "StegmannJCSDA/ScatteringBase", "max_issues_repo_head_hexsha": "dd7412c08061e2415a2dd2702d4497e6a3cb01aa", "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": "SizeGrid/main.f90", "max_forks_repo_name": "StegmannJCSDA/ScatteringBase", "max_forks_repo_head_hexsha": "dd7412c08061e2415a2dd2702d4497e6a3cb01aa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-20T10:40:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T10:40:49.000Z", "avg_line_length": 25.0813953488, "max_line_length": 58, "alphanum_fraction": 0.6249420491, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.8290170531674605}} {"text": "module random_mod\n\n use model_constants\n\n implicit none\n\n private\n double precision, parameter :: root_pi_over_8 = 0.626657068658 ! sqrt(kPI/8)\n\n integer, parameter :: size_of_normal_cdf_lookup_table = 1000000\n double precision, allocatable :: fast_cdf_lookup_table(:), cdf_lookup_table(:,:)\n \n interface normal_cdf\n module procedure real_normal_cdf, double_normal_cdf\n end interface\n \n public :: normal_cdf, box_muller_random, get_normal_from_cdf\n \ncontains\n \n !>------------------------------------------------\n !! Use the Box-Muller Transform to convert uniform to normal random deviates\n !!\n !! Note random_sample should be an allocated 1D real array\n !! On return, random_sample will be filled with random normal (0,1) data\n !!\n !! Caveat: this transform is unable to generate extremely high values (>6.66)\n !! Having switched to double precision it may do better now.\n !!\n !-------------------------------------------------\n subroutine box_muller_random(random_sample)\n implicit none\n real, intent(inout) :: random_sample(:)\n integer :: n,i\n\n double precision :: u1, u2, s\n double precision, allocatable :: double_random(:)\n\n n = size(random_sample)\n allocate(double_random(n))\n call random_number(double_random)\n\n do i=1,n,2\n u1 = double_random(i)\n if (i------------------------------------------------\n !! Computes an approximation to the normal CDF based on Aludaat and Alodat (2008)\n !!\n !! Aludaat, K.M. and Alodat, M.T. (2008). A note on approximating the normal distribution function. Applied Mathematical Sciences, Vol 2, no 9, pgs 425-429.\n !!\n !!------------------------------------------------\n function real_normal_cdf(normal) result(cdf)\n implicit none\n real :: normal\n real :: cdf\n \n cdf = 0.5 * (1 + sqrt((1 - exp(0 - (root_pi_over_8 * normal**2))) ))\n \n if (normal < 0) then\n cdf = 1 - cdf\n endif\n \n end function real_normal_cdf\n\n !>------------------------------------------------\n !! Computes an approximation to the normal CDF based on Aludaat and Alodat (2008)\n !!\n !! Aludaat, K.M. and Alodat, M.T. (2008). A note on approximating the normal distribution function. Applied Mathematical Sciences, Vol 2, no 9, pgs 425-429.\n !!\n !!------------------------------------------------\n function double_normal_cdf(normal) result(cdf)\n implicit none\n double precision :: normal\n double precision :: cdf\n \n cdf = 0.5 * (1 + sqrt((1.d0 - exp(0.d0 - (root_pi_over_8 * normal**2))) ))\n \n if (normal < 0) then\n cdf = 1 - cdf\n endif\n \n end function double_normal_cdf\n\n !>------------------------------------------------\n !! Create a look up table to convert from Uniform random number to Normal random\n !!\n !!------------------------------------------------\n subroutine create_cdf_lookup_table()\n implicit none\n \n integer :: i\n real :: normal_random_value, normal_step\n \n ! in case another thread beat this one to the lock after the if\n if (.not.allocated(fast_cdf_lookup_table)) then\n \n allocate(cdf_lookup_table(size_of_normal_cdf_lookup_table, 2))\n \n normal_random_value = (-5.5)\n normal_step = 11.0 / (size_of_normal_cdf_lookup_table - 1)\n \n do i = 1, size_of_normal_cdf_lookup_table\n cdf_lookup_table(i,1) = normal_random_value\n cdf_lookup_table(i,2) = normal_cdf(normal_random_value)\n\n normal_random_value = normal_random_value + normal_step\n enddo\n \n ! now invert this slow lookup table to create a fast lookup table\n allocate(fast_cdf_lookup_table(size_of_normal_cdf_lookup_table))\n \n do i = 1,size_of_normal_cdf_lookup_table\n fast_cdf_lookup_table(i) = look_up(dble(i) / size_of_normal_cdf_lookup_table, cdf_lookup_table)\n enddo\n \n deallocate(cdf_lookup_table)\n endif\n \n end subroutine create_cdf_lookup_table\n\n !>------------------------------------------------\n !! Perform a binary search through LUT to find value, then interpolate between the two closest entries. \n !!\n !!------------------------------------------------\n function look_up(value, LUT) result(output)\n implicit none\n double precision, intent(in) :: value\n double precision, intent(in) :: LUT(:,:)\n real :: output\n \n real :: fraction, denominator\n integer :: i,n\n integer :: step\n \n n = size(LUT, 1)\n i = n/2\n step = n/2\n \n ! perform a binary search\n do while(step/2.0 >= 1)\n step = (step+1) / 2\n if (LUT(i,2) > value) then\n i = max(1, i - step)\n else\n i = min(n, i + step)\n endif\n \n enddo\n \n ! figure out which side of this index we fall on and interpolate\n if (value > LUT(i,2)) then\n if (i==n) then\n output = LUT(i,1)\n else\n denominator = max(1e-20, (LUT(i+1,2) - LUT(i,2)))\n fraction = (value - LUT(i,2)) / denominator\n output = fraction * LUT(i+1,1) + (1-fraction) * LUT(i,1)\n endif\n else\n if (i==1) then\n output = LUT(i,1)\n else\n denominator = max(1e-20, (LUT(i,2) - LUT(i-1,2)))\n fraction = (LUT(i,2) - value) / denominator\n \n output = fraction * LUT(i-1,1) + (1-fraction) * LUT(i,1)\n endif\n endif\n end function look_up\n \n\n !>------------------------------------------------\n !! Calculate index into precomputed LUT to find cdf_value, then interpolate between the two closest entries. \n !!\n !!------------------------------------------------\n function get_normal_from_cdf(cdf_value) result(random_normal)\n implicit none\n real, intent(in) :: cdf_value\n real :: random_normal\n \n integer :: index\n double precision :: real_index\n double precision :: fraction\n \n if (.not.allocated(fast_cdf_lookup_table)) then\n !$omp critical(cdf_lookup)\n call create_cdf_lookup_table()\n !$omp end critical(cdf_lookup)\n endif\n\n ! in the fast look up table we can just compute the optimal index\n real_index = cdf_value * 1.0d0 * size_of_normal_cdf_lookup_table\n index = min(size_of_normal_cdf_lookup_table, max(1, nint( real_index)) )\n \n ! then interpolate between this index and the next closest\n if (index > real_index) then\n if (index == 1) then\n random_normal = fast_cdf_lookup_table(index)\n else\n fraction = (index - real_index)\n random_normal = (1-fraction) * fast_cdf_lookup_table(index) &\n + fraction * fast_cdf_lookup_table(max(1,index-1))\n endif\n else\n if (index == size_of_normal_cdf_lookup_table) then\n random_normal = fast_cdf_lookup_table(index)\n else\n fraction = (real_index - index)\n random_normal = (1-fraction) * fast_cdf_lookup_table(index) &\n + fraction * fast_cdf_lookup_table(min(size_of_normal_cdf_lookup_table,index+1))\n endif\n endif\n \n end function get_normal_from_cdf\n\n\nend module random_mod\n", "meta": {"hexsha": "628811efe6110b3006c37b544c3af705ba4b54dc", "size": 8201, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/random.f90", "max_stars_repo_name": "benlazarine/GARD", "max_stars_repo_head_hexsha": "567bdcf59a258bdf981b395f24a5af669da628b3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2016-11-04T15:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T14:54:57.000Z", "max_issues_repo_path": "src/utilities/random.f90", "max_issues_repo_name": "benlazarine/GARD", "max_issues_repo_head_hexsha": "567bdcf59a258bdf981b395f24a5af669da628b3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 42, "max_issues_repo_issues_event_min_datetime": "2016-11-04T15:07:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-20T08:56:47.000Z", "max_forks_repo_path": "src/utilities/random.f90", "max_forks_repo_name": "benlazarine/GARD", "max_forks_repo_head_hexsha": "567bdcf59a258bdf981b395f24a5af669da628b3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2016-11-03T15:33:58.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-15T06:33:55.000Z", "avg_line_length": 35.1974248927, "max_line_length": 160, "alphanum_fraction": 0.5259114742, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966656805269, "lm_q2_score": 0.8757869932689565, "lm_q1q2_score": 0.8290170476747682}} {"text": " subroutine gauleg(x1,x2,x,w,n)\nc Routine from Numerical Recipes (Press, Flannery, Teukolsky and Vetterling,\nc 1986, Cambridge University Press, ISBN 0 521 30811 9)\nc\nc Given the lower and upper limits of integration (X1, X2) and the number\nc of intervals (N), this routine returns arrays X and W of length N,\nc containing the abscissas and weights of the Gauss-Legendre N-point\nc quadrature formula.\nc\n implicit real*4 (a-h,o-z)\n REAL*4 X1,X2,X(N),W(N) \n parameter (eps=3.e-7)\nC\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(3.141592654*(i-.25)/(n+.5))\n z1 = 0.0\n do while (abs(z-z1).gt.eps)\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)/j\n end do\n pp=n*(z*p1-p2)/(z*z-1.0)\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.0*xl/((1.0-z*z)*pp*pp)\n w(n+1-i)=w(i)\n end do\n return\n end\n \n", "meta": {"hexsha": "1bbd311e856fa11964eaccc90ac0b99b654cb89f", "size": 1073, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Xerus/GSASII/fsource/powsubs/gauleg.for", "max_stars_repo_name": "pedrobcst/Xerus", "max_stars_repo_head_hexsha": "09df088e0207176df0d20715e1c9778d09d28250", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2021-12-10T03:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:35.000Z", "max_issues_repo_path": "Xerus/GSASII/fsource/powsubs/gauleg.for", "max_issues_repo_name": "pedrobcst/Xerus", "max_issues_repo_head_hexsha": "09df088e0207176df0d20715e1c9778d09d28250", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2022-02-24T11:09:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:17.000Z", "max_forks_repo_path": "Xerus/GSASII/fsource/powsubs/gauleg.for", "max_forks_repo_name": "pedrobcst/Xerus", "max_forks_repo_head_hexsha": "09df088e0207176df0d20715e1c9778d09d28250", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-25T16:26:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T16:26:54.000Z", "avg_line_length": 26.825, "max_line_length": 76, "alphanum_fraction": 0.5079217148, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966641739773, "lm_q2_score": 0.8757869900269366, "lm_q1q2_score": 0.8290170432864665}} {"text": "program gauss4by4\n implicit none\n real a(4,4),b(4),x(4),det\n integer i,j\n\n a(1,1)=2;a(1,2)= 4;a(1,3) = 5;a(1,4)= 2;\n a(2,1)=1;a(2,2)=-8;a(2,3) = 2;a(2,4)=-6;\n a(3,1)=4;a(3,2)= 1;a(3,3)=-10;a(3,4)=-2;\n a(4,1)=1;a(4,2)= 7;a(4,3) = 1;a(4,4)=-2;\n b(1) =9;b(2) =-3;b(3) = 1;b(4) =-3;\n call gaussian(a,b,4,x,det)\n print *,'X=',x(1),x(2),x(3),x(4),det\nend program gauss4by4\n\nsubroutine gaussian(a,b,n,x,det)\n implicit none\n real a(n,n),b(n),x(n),det,dd\n integer n,i,j,k,row,col\n row=n;col=n\n do k=1,row\n do i=k+1,row\n dd=a(i,k)/a(k,k)\n do j = k+1,col\n a(i,j)=a(i,j)-dd*a(k,j)\n enddo\n b(i)=b(i)-dd*b(k)\n enddo\n enddo\n x(n)=b(n)/a(n,n)\n do i = n-1,1,-1\n dd=b(i)\n do j = i+1,n\n dd=dd-a(i,j)*x(j)\n enddo\n x(i)=dd/a(i,i)\n enddo\n det = a(1,1)\n do i=2,n\n det = det*a(i,i)\n enddo\n\nend subroutine gaussian", "meta": {"hexsha": "2f8b1bb36c606d985a98056d02fe667f1f203af2", "size": 979, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "90and95/solveLinear/gauss.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/gauss.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/gauss.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": 23.3095238095, "max_line_length": 44, "alphanum_fraction": 0.431052094, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075722839016, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8288924368157186}} {"text": "C File: arrays-basic-07.f\nC Illustrates: transposition of a 2-D matrix\n\n\tprogram main\n\timplicit none\n\n\tinteger, dimension(3,5) :: A\n\tinteger, dimension(5,3) :: B\n\tinteger :: i, j\n\nC Initialize matrix A\n\tdo i = 1,3\n\t do j = 1,5\n\t A(i,j) = (i*j)+(i+j)\n\t end do\n\tend do\n\nC Transpose A into B\n\tdo i = 1,3\n\t do j = 1,5\n\t B(j,i) = A(i,j)\n\t end do\n\tend do\n\nC Print out the results\n 10 format('A:', 5(X,I4))\n 11 format('')\n 12 format('B:', 3(X,I4))\n\n\tdo i = 1,3\n\t write(*,10) A(i,1), A(i,2), A(i,3), A(i,4), A(i,5)\n\tend do\n\n\twrite(*,11)\n\n\tdo i = 1,5\n\t write(*,12) B(i,1), B(i,2), B(i,3)\n\tend do\n\n\tstop\n\tend program main\n", "meta": {"hexsha": "8b4d9142ae703fc83ec4243d92de2e160888723d", "size": 656, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/arrays/arrays-basic-07.f", "max_stars_repo_name": "cthoyt/delphi", "max_stars_repo_head_hexsha": "3df2de639905453f5d28d7a7b3b9f7e5a7a1fb0d", "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": "tests/data/arrays/arrays-basic-07.f", "max_issues_repo_name": "cthoyt/delphi", "max_issues_repo_head_hexsha": "3df2de639905453f5d28d7a7b3b9f7e5a7a1fb0d", "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/data/arrays/arrays-basic-07.f", "max_forks_repo_name": "cthoyt/delphi", "max_forks_repo_head_hexsha": "3df2de639905453f5d28d7a7b3b9f7e5a7a1fb0d", "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.619047619, "max_line_length": 55, "alphanum_fraction": 0.5304878049, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.8918110368115783, "lm_q1q2_score": 0.8288852032067305}} {"text": "\tFUNCTION PR_TMCF ( tmpc )\nC************************************************************************\nC* PR_TMCF\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPF from TMPC. The following equation is *\nC* used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPF = ( TMPC * 9 / 5 ) + 32\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMCF ( 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*\tTMPC\t\tREAL \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_TMCF\t\tREAL \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* J. Woytek/GSFC\t10/82\tOriginal source code\t\t\t*\nC* M. Goodman/RDS\t 9/84\tAdded error branch\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************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC*\n\tPARAMETER\t( RPRM = 9.0 / 5.0 )\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpc ) ) THEN\n\t PR_TMCF = RMISSD\n\t ELSE\n\t PR_TMCF = ( tmpc * RPRM ) + 32.\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "2d3d2f6d171dad777157624c5b7d02de5213ef97", "size": 1171, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmcf.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/prtmcf.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/prtmcf.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.0256410256, "max_line_length": 73, "alphanum_fraction": 0.4346712212, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452771, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8288700283010527}} {"text": "!-----Area_Circle----------------------------------------------------\n!\n! Function to compute the area of a circle of given radius\n!\n!---------------------------------------------------------------------\nFUNCTION Area_Circle(r)\nUSE Circle, ONLY : Pi\n\nIMPLICIT NONE\nREAL :: Area_Circle\nREAL, INTENT(IN) :: r\n\nArea_Circle = Pi * r * r\n\nEND FUNCTION Area_Circle", "meta": {"hexsha": "744d6dccc39bc88aae4731cdfa6541ab3998c7a5", "size": 359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/fortran/old_circle.f90", "max_stars_repo_name": "dvuckovic/ecbuild", "max_stars_repo_head_hexsha": "63d24861fc1535d596645e6814fc075b5004a992", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2018-03-08T12:05:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T09:25:23.000Z", "max_issues_repo_path": "examples/fortran/old_circle.f90", "max_issues_repo_name": "dvuckovic/ecbuild", "max_issues_repo_head_hexsha": "63d24861fc1535d596645e6814fc075b5004a992", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 38, "max_issues_repo_issues_event_min_datetime": "2018-06-28T10:31:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-10T21:46:54.000Z", "max_forks_repo_path": "examples/fortran/old_circle.f90", "max_forks_repo_name": "dvuckovic/ecbuild", "max_forks_repo_head_hexsha": "63d24861fc1535d596645e6814fc075b5004a992", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2018-07-05T22:57:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T21:09:24.000Z", "avg_line_length": 23.9333333333, "max_line_length": 70, "alphanum_fraction": 0.4707520891, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.959762052772658, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8286505022483053}} {"text": "module primes\n use, intrinsic :: iso_fortran_env\n implicit none\n private\n \n interface primesUpTo\n module procedure primesUpTo_int8, primesUpTo_int32\n end interface\n \n interface isPrime\n module procedure isPrime_int8, isPrime_int32\n end interface\n \n interface randomPrime\n module procedure randomPrime_int8, randomPrime_int32\n end interface\n \n public :: primesUpTo, isPrime, randomPrime\n \n contains\n function primesUpTo_int8(n) result(primes)\n integer(int8), intent(in) :: n\n integer(int8), dimension(:), allocatable :: primes\n integer(int8), dimension(:), allocatable :: temp\n logical, dimension(:), allocatable :: fullset\n integer(int8) :: i, j\n \n allocate(primes(0))\n if (n > 1_int8) then ! basic sieve\n allocate(fullset(n))\n fullset = .true.\n do i = 2,n\n if (fullset(i)) then\n allocate(temp(size(primes) + 1))\n temp(:size(primes)) = primes\n temp(size(primes) + 1) = i\n deallocate(primes)\n allocate(primes(size(temp)), source=temp)\n deallocate(temp)\n do j = 2_int8 * i, n, i\n fullset(j) = .false.\n end do\n end if\n end do\n deallocate(fullset)\n end if\n end function\n \n function primesUpTo_int32(n) result(primes)\n integer(int32), intent(in) :: n\n integer(int32), dimension(:), allocatable :: primes\n integer(int32), dimension(:), allocatable :: temp\n logical, dimension(:), allocatable :: fullset\n integer(int32) :: i, j\n \n allocate(primes(0))\n if (n > 1_int32) then ! basic sieve\n allocate(fullset(n))\n fullset = .true.\n do i = 2,n\n if (fullset(i)) then\n allocate(temp(size(primes) + 1))\n temp(:size(primes)) = primes\n temp(size(primes) + 1) = i\n deallocate(primes)\n allocate(primes(size(temp)), source=temp)\n deallocate(temp)\n do j = 2_int32 * i, n, i\n fullset(j) = .false.\n end do\n end if\n end do\n deallocate(fullset)\n end if\n end function\n \n function isPrime_int8(n) result(t)\n integer(int8), intent(in) :: n\n logical :: t\n integer(int8), dimension(:), allocatable :: primes\n integer :: i\n \n t = .true.\n primes = primesUpTo_int8(floor(sqrt(real(n)), int8))\n do i = 1,size(primes)\n if (mod(n, primes(i)) == 0_int8) then\n t = .false.\n exit\n end if\n end do\n deallocate(primes)\n end function\n \n function isPrime_int32(n) result(t)\n integer(int32), intent(in) :: n\n logical :: t\n integer(int32), dimension(:), allocatable :: primes\n integer :: i\n \n t = .true.\n primes = primesUpTo_int32(floor(sqrt(real(n)), int32))\n do i = 1,size(primes)\n if (mod(n, primes(i)) == 0_int32) then\n t = .false.\n exit\n end if\n end do\n deallocate(primes)\n end function\n \n recursive function randomPrime_int8(min, max) result(p)\n integer(int8), intent(in) :: min, max\n integer(int8) :: p\n logical :: first = .true.\n real(real32) :: r\n \n if (first) then\n first = .false.\n call RANDOM_SEED()\n end if\n call RANDOM_NUMBER(r)\n p = floor(r * ((max - 1) - min + 1), int8) + min\n if (.not. isPrime_int8(p)) then\n p = randomPrime_int8(min, max)\n end if\n end function\n \n recursive function randomPrime_int32(min, max) result(p)\n integer(int32), intent(in) :: min, max\n integer(int32) :: p\n logical :: first = .true.\n real(real32) :: r\n \n if (first) then\n first = .false.\n call RANDOM_SEED()\n end if\n call RANDOM_NUMBER(r)\n p = floor(r * ((max - 1) - min + 1), int32) + min\n if (.not. isPrime_int32(p)) then\n p = randomPrime_int32(min, max)\n end if\n end function\nend module", "meta": {"hexsha": "fbf8a5846224ec9c8806e3947a00dce43fdde0b9", "size": 4469, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "primes.f95", "max_stars_repo_name": "jaketimothy/fortran-datastructures", "max_stars_repo_head_hexsha": "afb1a9cc28ace383094852540152a3c0bb3401ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-01-06T11:55:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T11:34:07.000Z", "max_issues_repo_path": "primes.f95", "max_issues_repo_name": "jaketimothy/fortran-datastructures", "max_issues_repo_head_hexsha": "afb1a9cc28ace383094852540152a3c0bb3401ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "primes.f95", "max_forks_repo_name": "jaketimothy/fortran-datastructures", "max_forks_repo_head_hexsha": "afb1a9cc28ace383094852540152a3c0bb3401ee", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-08T18:12:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-23T11:34:09.000Z", "avg_line_length": 31.0347222222, "max_line_length": 62, "alphanum_fraction": 0.49697919, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8774767874818409, "lm_q1q2_score": 0.8284932796885549}} {"text": "module gcd_lcm_pf_module\n \n implicit none\n\n private\n public :: gcd\n public :: lcm\n public :: prime_factorization\n\ncontains\n\n integer function gcd( m_in, n_in )\n implicit none\n integer, intent(in) :: m_in, n_in\n integer :: m,n,m_tmp,loop\n if ( m_in >= n_in ) then\n m = m_in\n n = n_in\n else\n m = n_in\n n = m_in\n end if\n do\n if ( n == 0 ) exit\n m_tmp = n\n n = mod( m, n )\n m = m_tmp\n end do\n gcd = m\n end function gcd\n\n integer function lcm( m_in, n_in )\n implicit none\n integer, intent(in) :: m_in, n_in\n lcm = m_in * n_in / gcd( m_in, n_in )\n end function lcm\n\n subroutine prime_factorization( n_in, ifact )\n implicit none\n integer,intent(in) :: n_in\n integer,intent(out) :: ifact(:)\n integer :: n,i,j,m\n ifact(:)=0\n ifact(1)=1\n n = n_in\n m = n\n loop_j : do j = 1, n_in\n loop_i : do i = 2, n\n if ( mod(m,i) == 0 ) then\n m = m/i\n ifact(i) = ifact(i) + 1\n exit loop_i\n else if ( i == n ) then\n exit loop_j\n end if\n end do loop_i\n n = m\n end do loop_j\n end subroutine prime_factorization\n\nend module gcd_lcm_pf_module\n", "meta": {"hexsha": "616b50ca73cf1e8c96850c2797480bb58a17823e", "size": 1205, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gcd_lcm_pf_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/gcd_lcm_pf_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/gcd_lcm_pf_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": 19.435483871, "max_line_length": 47, "alphanum_fraction": 0.5443983402, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992960608886, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.8283777244618576}} {"text": "!Numerical solution to non-linear equations using Newton and bisection methods\n!\n!(c) 2016 Matteo Paolieri\n!LICENSE: The MIT License (MIT)\n\nmodule functions \n\n contains\n\n double precision function es1(x) !function to solve\n double precision :: x\n es1 = EXP(x)-(x+1)**(x-1) \n end\n \n double precision function es1d(x) !derivative of es1\n double precision :: x\n es1d = EXP(x)-(x+1)**(x-2)*(x+(x+1)*log(x+1)-1)\n end\n \nend module functions\n\nmodule metodi\n\n contains\n\n subroutine bisection (a,b,f,tolx,x,steps) !bisection method\n \n implicit double precision (A-H, O-Z) \n\n interface\n double precision function f(x)\n implicit double precision (A-H, O-Z)\n end function f\n end interface\n \n fa = f(a)\n fb = f(b)\n x = (a+b)/2.0\n fx = f(x)\n \n c = log(b-a)/log(2.0) !log_2(b-a)\n d = log(tolx)/log(2.0) !log_2(tolx)\n kmax = ceiling(real(c-d)) \n\n steps = kmax\n \n do k = 2, kmax\n \n!~ f1x = |f'(x)| (using incremental ratio) \n \n f1x = abs((fb-fa)/(b-a))\n if (abs(fx) .le. tolx*f1x) then !arrest criteria\n steps = k-1\n exit \n else if (fa*fx > 0) then \n b = x \n fb = fx\n else \n a = x\n fa = fx\n end if\n x = (a+b)/2\n fx = f(x)\n end do\n \n!~ arrest criteria: |f(x_i)| <= tolx*|f'(xi)|\n\n end subroutine bisection\n \n subroutine newton(x0, f, f1, tolx, kmax, x, steps) \n\n implicit double precision (A-H, O-Z)\n interface\n double precision function f(x)\n implicit double precision (A-H, O-Z)\n end function f\n \n double precision function f1(x)\n implicit double precision (A-H, O-Z)\n end function f1\n end interface \n \n fx = f(x0)\n f1x = f1(x0)\n x = x0 - fx/f1x ! first step of Newton's method\n k = 0\n \n do while ((ktolx)) ! arrest criteria = |x(k+1)-x(k)|tolx) then\n print *, \"Newton: the method does not converge.\"\n end if\n \n steps = k\n \n end subroutine newton\n \nend module metodi\n\nprogram nonlin_eq\n \n use metodi\n use functions\n \n implicit double precision (A-H, O-Z)\n\n a = 2.0\n b = 4.5\n tolx = 1E-10\n \n call bisection(a, b, es1, tolx, xb, stepsb) !xb and stepsb are output\n \n print *, \"______ BISECTION ______\"\n print '(a, f10.5)', \"x = \", xb\n print '(a, f10.0)', \"steps = \", stepsb\n \n x0 = 3.0\n kmax = 100\n \n call newton(x0, es1, es1d, tolx, kmax, xn, stepsn) !xn and stepsn are output\n \n print *, \"______ NEWTON ______\"\n print '(a, f10.5)', \"x = \", xn\n print '(a, f10.0)', \"steps = \", stepsn\n \nend program nonlin_eq\n", "meta": {"hexsha": "d2742b00c9a5b6a9c8dfbe5b39ce939e45773a38", "size": 3230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "non-linear equations.f90", "max_stars_repo_name": "mtplr/Fortran-non-linear-equation", "max_stars_repo_head_hexsha": "21d2083750eec9436aef359cafbec2835b5dac37", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "non-linear equations.f90", "max_issues_repo_name": "mtplr/Fortran-non-linear-equation", "max_issues_repo_head_hexsha": "21d2083750eec9436aef359cafbec2835b5dac37", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "non-linear equations.f90", "max_forks_repo_name": "mtplr/Fortran-non-linear-equation", "max_forks_repo_head_hexsha": "21d2083750eec9436aef359cafbec2835b5dac37", "max_forks_repo_licenses": ["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.2857142857, "max_line_length": 90, "alphanum_fraction": 0.4696594427, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012762876286, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.8283204605893435}} {"text": "MODULE precision\n ! dp = double precision\n INTEGER, PARAMETER:: dp = SELECTED_REAL_KIND(12)\nEND MODULE precision\n\nPROGRAM Newton_Raphson_Method\n USE precision\n IMPLICIT NONE\n\n REAL(KIND = dp):: x0, x1, f0, fun, fprime, error, root\n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter value of x0 : \"\n ! For this question enter x0\n READ(*, *) x0\n\n error = 1e-6\n \n DO\n fun = Functn(x0)\n fprime = Functn_Prime(x0)\n x1 = x0 - fun / fprime\n f0 = Functn(x1)\n\n IF (f0 .EQ. 0.0_dp) THEN\n root = x1\n WRITE(*, *) \"Root is: \", root\n RETURN\n ENDIF\n\n IF (abs((x1 - x0)/x1) .LT. error) THEN \n root = x1\n WRITE(*, *) \"Root is: \", root\n RETURN\n ELSE \n x0 = x1\n ENDIF\n\n ENDDO\n\n CONTAINS\n REAL(KIND = dp) FUNCTION Functn(x)\n USE precision\n IMPLICIT NONE \n REAL(KIND = dp):: x, rho\n rho = 4.0_dp\n Functn = x*tan(x) - sqrt(rho**2 - x**2)\n RETURN \n END FUNCTION Functn\n\n REAL(KIND = dp) FUNCTION Functn_Prime(x)\n USE precision\n IMPLICIT NONE \n REAL(KIND = dp):: x, rho\n rho = 4.0_dp\n Functn_Prime = (x/(cos(x)**2)) + tan(x) + (x/sqrt((rho**2) - (x**2))) \n RETURN \n END FUNCTION Functn_Prime\n\nEND PROGRAM Newton_Raphson_Method\n", "meta": {"hexsha": "84778287adf5b302b15cb164c2044af729cce45b", "size": 1374, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6. HA6 - Root Finding Method/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": "6. HA6 - Root Finding Method/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": "6. HA6 - Root Finding Method/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": 23.2881355932, "max_line_length": 78, "alphanum_fraction": 0.5131004367, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8757869835428966, "lm_q1q2_score": 0.8283204441150783}} {"text": "! -*- mode: f90 -*-\n!\n! $Id: mandelbrot.1.ifc.code,v 1.13 2010-02-20 17:36:19 igouy-guest Exp $ ; $Name: $\n!\n! The Great Computer Language Shootout\n! http://shootout.alioth.debian.org/\n!\n! Simon Geard, 6/1/05\n!\n! Adapted mandelbrot.c by Greg Buchholz\n!\n! Modified to use explicit kind parameters by Jason Blevins, 4/10/10.\n!\n! Building info.\n! ==============\n!\n! Linux - using the Intel Fortran90 compiler:\n!\n! ifort mandelbrot.f90 -O3 -static-libcxa -o mandelbrot\n!\nprogram mandelbrot\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n integer w, h, x, y, bit_num\n integer(kind=1) byte_acc\n integer(kind=1), parameter :: K0 = 0\n integer(kind=1), parameter :: K1 = 1\n integer, parameter :: iter = 50\n real(kind=dp), parameter :: limit2 = 4.0_dp\n integer i\n character(len=8) argv\n complex(kind=dp) :: Z, C\n logical debug, in_mandelbrot\n\n call getarg(1,argv)\n read(argv,*) w\n h = w\n bit_num = 0\n byte_acc = K0\n ! Output pbm header\n write(*,'(a)') 'P4'\n write(*,'(i0,a,i0)') w,' ',h\n do y=0,h-1\n do x=0,w-1\n C = cmplx(2.0d0*x/w-1.5d0,2.0d0*y/h-1.0d0, dp)\n Z = (0.0d0,0.0d0)\n in_mandelbrot = .true.\n do i=0,iter-1\n Z = Z**2 + C\n if (real(Z*conjg(Z)) > limit2) then\n in_mandelbrot = .false.\n exit\n end if\n end do\n if (in_mandelbrot) then\n ! Inside the set so set this bit to 1\n byte_acc = ior(ishft(byte_acc,1),K1)\n else\n ! Outside the set so set this bit to 0\n byte_acc = ishft(byte_acc,1)\n end if\n\n bit_num = bit_num + 1\n if (bit_num == 8) then\n ! All bits set so output them\n write(*,'(a1)',advance='no') char(byte_acc)\n byte_acc = K0\n bit_num = 0\n\n elseif (x == w-1) then\n ! End of a row so left-justify the bits we have and output them\n byte_acc = ishft(byte_acc,8-mod(w,8))\n write(*,'(a1)',advance='no') char(byte_acc)\n byte_acc = K0\n bit_num = 0\n\n end if\n\n end do\n end do\nend program mandelbrot\n", "meta": {"hexsha": "30765ac4f2047cbc3ee89bf1223d66d8fcf9a6a8", "size": 2116, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "shootout/mandelbrot.ifc-1.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": "shootout/mandelbrot.ifc-1.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": "shootout/mandelbrot.ifc-1.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": 25.8048780488, "max_line_length": 85, "alphanum_fraction": 0.5576559546, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.8281441183859105}} {"text": "program perkalian_matrix\n implicit none\n\n integer :: i,j,k\n real :: a(3,3), b(3,3), c(3,3)\n\n ! Defenisikan nilai dalam matrix\n a(1,1) = 1\n a(1,2) = 2\n a(1,3) = 3\n a(2,1) = 4\n a(2,2) = 5\n a(2,3) = 6\n a(3,1) = 7\n a(3,2) = 8\n a(3,3) = 9\n\n b(1,1) = 2\n b(1,2) = 4\n b(1,3) = 6\n b(2,1) = 1\n b(2,2) = 3\n b(2,3) = 5\n b(3,1) = 1\n b(3,2) = 2\n b(3,3) = 3\n\n ! Cara lain menampilkan matrix\n write(*,*) 'Matrix a'\n do i = 1,3\n write(*,*) (a(i,j), j=1,3)\n end do\n\n write(*,*)\n\n write(*,*) 'Matrix b'\n do i = 1,3\n write(*,*) (b(i,j), j=1,3)\n end do\n\n write(*,*)\n\n ! PERKALIAN MATRIX\n ! Mengalikan matrix dengan suatu nilai/konstanta\n write(*,*) 'Mengalikan matrix dengan suatu nilai/konstanta'\n do i = 1,3\n write(*,*) (a(i,j) * 2, j = 1,3)\n end do\n\n write(*,*)\n\n ! Mengalikan matrix dengan matrix\n do i = 1,3\n do j = 1,3\n c(i,j) = 0\n do k = 1,3\n c(i,j) = c(i,j) + (a(i,k) * b(k,j))\n end do\n end do\n end do\n\n ! Menampilkan hasil perkalian matrix dengan matrix\n write(*,*) 'Menampilkan hasil perkalian matrix dengan matrix'\n do i = 1,3\n write(*,*) (c(i,j), j = 1,3)\n end do\n\nend program perkalian_matrix", "meta": {"hexsha": "1f9a5c197087ac07b4aa6a35c92755d962322363", "size": 1306, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "perkalian_matrix.f95", "max_stars_repo_name": "auliakhalqillah/AlgortimaDasar", "max_stars_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "perkalian_matrix.f95", "max_issues_repo_name": "auliakhalqillah/AlgortimaDasar", "max_issues_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "perkalian_matrix.f95", "max_forks_repo_name": "auliakhalqillah/AlgortimaDasar", "max_forks_repo_head_hexsha": "351b68ce649c9b409d263d5fee83bbfa671316ca", "max_forks_repo_licenses": ["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.2058823529, "max_line_length": 65, "alphanum_fraction": 0.4586523737, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8280842053725713}} {"text": "SUBROUTINE interpolate_1D(x,y,x1,x2,y1,y2)\n! Subroutine interpolates in 1 dimension, given\n! Bounding independent coordinates x1,x2\n! Corresponding dependent variables y1,y2\n! Input independent coordinate x\n! Desired interpolant y\n\nimplicit none\n\nreal :: x1,x2,y1,y2,x,y\nreal :: grad, inter\n\n!print*, 'Calling interpolate 1D'\n\ngrad = (y2-y1)/(x2-x1)\ninter = y2 - grad*x2\n\ny = grad*x + inter\n\n\n!print*, x,y,x1,x2,y1,y2, grad,inter\n\nEND SUBROUTINE interpolate_1D\n", "meta": {"hexsha": "f07a169d3f5583f69ec2ede4e8ed7ec8f1703682", "size": 461, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/disc/interpolate_1D.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/disc/interpolate_1D.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/disc/interpolate_1D.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": 19.2083333333, "max_line_length": 47, "alphanum_fraction": 0.7353579176, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8740772220439509, "lm_q1q2_score": 0.8280841882806235}} {"text": "program intrinsics_18\n! This program tests all trigonometric intrinsics, both in declarations\n! and in executable statements. Single and double precision, real only.\ninteger, parameter :: dp = kind(0.d0)\n\nreal, parameter :: &\n s1 = sin(0.5), &\n s2 = cos(0.5), &\n s3 = tan(0.5), &\n s4 = asin(0.5), &\n s5 = acos(0.5), &\n s6 = atan(0.5), &\n s7 = sinh(0.5), &\n s8 = cosh(0.5), &\n s9 = tanh(0.5), &\n s10 = asinh(0.5), &\n s11 = acosh(1.5), &\n s12 = atanh(0.5)\n\nreal(dp), parameter :: &\n d1 = sin(0.5_dp), &\n d2 = cos(0.5_dp), &\n d3 = tan(0.5_dp), &\n d4 = asin(0.5_dp), &\n d5 = acos(0.5_dp), &\n d6 = atan(0.5_dp), &\n d7 = sinh(0.5_dp), &\n d8 = cosh(0.5_dp), &\n d9 = tanh(0.5_dp), &\n d10 = asinh(0.5_dp), &\n d11 = acosh(1.5_dp), &\n d12 = atanh(0.5_dp)\n\nreal :: x, x2\nreal(dp) :: y, y2\n\nx = 0.5\ny = 0.5_dp\nx2 = 1.5\ny2 = 1.5_dp\n\nprint *, sin(0.5), sin(0.5_dp), s1, d1, sin(x), sin(y)\nprint *, cos(0.5), cos(0.5_dp), s2, d2, cos(x), cos(y)\nprint *, tan(0.5), tan(0.5_dp), s3, d3, tan(x), tan(y)\n\nprint *, asin(0.5), asin(0.5_dp), s4, d4, asin(x), asin(y)\nprint *, acos(0.5), acos(0.5_dp), s5, d5, acos(x), acos(y)\nprint *, atan(0.5), atan(0.5_dp), s6, d6, atan(x), atan(y)\n\nprint *, sinh(0.5), sinh(0.5_dp), s7, d7, sinh(x), sinh(y)\nprint *, cosh(0.5), cosh(0.5_dp), s8, d8, cosh(x), cosh(y)\nprint *, tanh(0.5), tanh(0.5_dp), s9, d9, tanh(x), tanh(y)\n\nprint *, asinh(0.5), asinh(0.5_dp), s10, d10, asinh(x), asinh(y)\nprint *, acosh(1.5), acosh(1.5_dp), s11, d11, acosh(x2), acosh(y2)\nprint *, atanh(0.5), atanh(0.5_dp), s12, d12, atanh(x), atanh(y)\n\nend\n", "meta": {"hexsha": "5df34f2c89f2ae3b43204cbb89dd8f10d10940c4", "size": 1615, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_18.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_18.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_18.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.3728813559, "max_line_length": 71, "alphanum_fraction": 0.5442724458, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811631528337, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8280731726657835}} {"text": "submodule(forlab) forlab_degcir\n !degree circular functions\n !! Version: experimental\n !!\n !! Discussion:\n !! ----\n !! https://fortran-lang.discourse.group/t/fortran-function-return-value-polymorphism/1350/5\n use forlab_kinds\n implicit none\ncontains\n\n ! acosd\n !-----------------------------------------------------------------------\n ! acosd computes the inverse cosine in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = acosd(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = acosd(x) returns the inverse cosine of the elements in x in\n ! degrees. For real elements of x in the domain [-1,1], acosd returns\n ! values in the range [0,180]. For values of x outside this range,\n ! acosd returns NaN (Not a Number).\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = acosd(1.)\n ! 1.\n !\n ! y = acosd(2.)\n ! NaN\n !\n ! x = [ -1., 0., 1. ]\n ! y = acosd(x)\n ! 180. 90. 0.\n\n\n ! asind\n !-----------------------------------------------------------------------\n ! asind computes the inverse sine in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = asind(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = asind(x) returns the inverse sine of the elements in x in degrees.\n ! For real elements of x in the domain [-1,1], asind returns values in\n ! the range [-90,90]. For values of x outside this range, asind returns\n ! NaN (Not a Number).\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = asind(1.)\n ! 90.\n !\n ! y = asind(2.)\n ! NaN\n !\n ! x = [ -1., 0., 1. ]\n ! y = asind(x)\n ! -90. 0. 90.\n\n\n ! atand\n !-----------------------------------------------------------------------\n ! atand computes the inverse tangent in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = atand(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = atand(x) returns the inverse tangent of the elements in x in\n ! degrees. For real elements of x in the domain [-Inf,Inf], atand\n ! returns values in the range [-90,90].\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = atand(0.)\n ! 0.\n !\n ! y = atand(50.)\n ! 88.8542328\n !\n ! x = [ -50., 0., 50. ]\n ! y = atand(x)\n ! -88.8542328 0. 88.8542328\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 acosd_qp\n acosd_qp=acos(x)*180/pi_qp\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 asind_qp\n asind_qp=asin(x)*180/pi_qp\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 atand_qp\n atand_qp=atan(x)*180/pi_qp\n end procedure\n\n ! sind\n !-----------------------------------------------------------------------\n ! sind computes the sine of argument in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = sind(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = sind(x) returns the sine of the elements in x, which are expressed\n ! in degrees.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = sind(90.)\n ! 1.\n !\n ! x = [ 0., 90., 180., 270. ]\n ! y = sind(x)\n ! 0. 1. 0. -1.\n\n ! cosd\n !-----------------------------------------------------------------------\n ! cosd computes the cosine of argument in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = cosd(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = cosd(x) returns the cosine of the elements in x, which are\n ! expressed in degrees.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = cosd(0.)\n ! 1.\n !\n ! x = [ 0., 90., 180., 270. ]\n ! y = cosd(x)\n ! 1. 0. -1. 0.\n\n ! tand\n !-----------------------------------------------------------------------\n ! tand computes the tangent of argument in degrees.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = tand(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = tand(x) returns the tangent of the elements in x, which are\n ! expressed in degrees.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = tand(0.)\n ! 0.\n !\n ! x = [ 0., 90., 180., 270. ]\n ! y = tand(x)\n ! 0. Inf 0. -Inf\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 cosd_qp\n cosd_qp=cos(x*pi_qp/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 sind_qp\n sind_qp=sin(x*pi_qp/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\n module procedure tand_qp\n tand_qp=tan(x*pi_qp/180)\n end procedure\n\nend submodule\n", "meta": {"hexsha": "60365af529712ba2810f160fe3b74e8859ffd209", "size": 6317, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_degcir.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_degcir.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_degcir.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": 27.3463203463, "max_line_length": 95, "alphanum_fraction": 0.3952825708, "num_tokens": 1488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.89181104831338, "lm_q1q2_score": 0.827965223920188}} {"text": "!!# MODULE <>\nMODULE FUN_CoefficientBinomial\n\n!!## PURPOSE\n!! Defines function which produces the\n!! binomial coefficient,\n!\n!! / n \\ n!\n!! | | = -----------\n!! \\ k / (n-k)! k!\n!\n!! or in \\LaTeX, the formula is,\n!! $$\n!! \\left( {\\begin{array}{*{20}c} n \\\\ k \\\\ \\end{array}} \\right) = \\frac{{n!}}{{k!\\left( {n - k} \\right)!}}\n!! $$\n!\n\n!!## USAGE\n!\n!! y = CoefficientBinomial(n,k)\n!!\n!! where is , and are integers,\n!! , , ,\n!! or \n\n\n!!## EXTERNAL KINDS\n!! * kind of the real function return value\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp,KIND_I1,KIND_I2,KIND_I4,KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))\n\n\n!!## EXTERNAL PROCEDURES\nUSE FUN_FactorialLn,ONLY: FactorialLn !!((08-B-FUN_FactorialLn.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n\n!!## DEFAULT ACCESS\n!! * debug with PUBLIC default access, run with PRIVATE default access\nPRIVATE\n\n!!## FUNCTION OVERLOADING\nINTERFACE CoefficientBinomial\n MODULE PROCEDURE CoefficientBinomial_I1\n MODULE PROCEDURE CoefficientBinomial_I2\n MODULE PROCEDURE CoefficientBinomial_I4\n MODULE PROCEDURE CoefficientBinomial_I8\nEND INTERFACE\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: CoefficientBinomial\n\n!!## CONTAINED PROCEDURES\nCONTAINS\n\n!!### CoefficientBinomial_I1\nPURE ELEMENTAL FUNCTION CoefficientBinomial_I1( n , k ) RESULT(y)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I1 !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.hdr\"\n!!--begin--\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n!!### CoefficientBinomial_I2\nPURE ELEMENTAL FUNCTION CoefficientBinomial_I2( n , k ) RESULT(y)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I2 !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.hdr\"\n!!--begin--\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n!!### CoefficientBinomial_I4\nPURE ELEMENTAL FUNCTION CoefficientBinomial_I4( n , k ) RESULT(y)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I4 !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.hdr\"\n!!--begin--\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n!!### CoefficientBinomial_I8\nPURE ELEMENTAL FUNCTION CoefficientBinomial_I8( n , k ) RESULT(y)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.hdr\"\n!!--begin--\nINCLUDE \"10-B-FUN_CoefficientBinomial.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nEND MODULE\n", "meta": {"hexsha": "d39ad035d195abcddac2efdef696b3a6f48eb13b", "size": 2973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/10-B-FUN_CoefficientBinomial.f90", "max_stars_repo_name": "wawiesel/tapack", "max_stars_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/10-B-FUN_CoefficientBinomial.f90", "max_issues_repo_name": "wawiesel/tapack", "max_issues_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/10-B-FUN_CoefficientBinomial.f90", "max_forks_repo_name": "wawiesel/tapack", "max_forks_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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.0303030303, "max_line_length": 112, "alphanum_fraction": 0.6606121763, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8278267770434972}} {"text": "PURE SUBROUTINE sub_ttest_ind(arr1, arr2, similarVar, t, p)\n ! NOTE: See https://en.wikipedia.org/wiki/Student's_t-test\n ! * \"Equal or unequal sample sizes, similar variances\" section\n ! * \"Equal or unequal sample sizes, unequal variances\" section\n ! NOTE: See https://en.wikipedia.org/wiki/Welch's_t-test\n ! NOTE: See https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html\n\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n LOGICAL(kind = INT8), INTENT(in) :: similarVar\n REAL(kind = REAL64), INTENT(out) :: p\n REAL(kind = REAL64), INTENT(out) :: t\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: arr1\n REAL(kind = REAL64), DIMENSION(:), INTENT(in) :: arr2\n\n ! Declare internal variables ...\n INTEGER(kind = INT64) :: n1\n INTEGER(kind = INT64) :: n2\n REAL(kind = REAL64) :: dof\n REAL(kind = REAL64) :: s\n REAL(kind = REAL64) :: mean1\n REAL(kind = REAL64) :: mean2\n REAL(kind = REAL64) :: var1\n REAL(kind = REAL64) :: var1n1\n REAL(kind = REAL64) :: var2\n REAL(kind = REAL64) :: var2n2\n\n ! Find size of arrays ...\n n1 = SIZE(arr1, kind = INT64)\n n2 = SIZE(arr2, kind = INT64)\n\n ! Find means ...\n mean1 = func_mean(arr1)\n mean2 = func_mean(arr2)\n\n ! Find variances ...\n var1 = func_var(arr1, 1_INT64)\n var2 = func_var(arr2, 1_INT64)\n\n ! Check if the variances are supposed to be similar ...\n IF(similarVar)THEN\n ! Calculate the degrees-of-freedom, the variance and the t-statistic ...\n dof = REAL(n1 + n2 - 2_INT64, kind = REAL64)\n s = SQRT((REAL(n1 - 1_INT64, kind = REAL64) * var1 + REAL(n2 - 1_INT64, kind = REAL64) * var2) / dof)\n t = (mean1 - mean2) / (s * SQRT(1.0e0_REAL64 / REAL(n1, kind = REAL64) + 1.0e0_REAL64 / REAL(n2, kind = REAL64)))\n ELSE\n ! Create short-hands ...\n var1n1 = var1 / REAL(n1, kind = REAL64)\n var2n2 = var2 / REAL(n2, kind = REAL64)\n\n ! Calculate the degrees-of-freedom, the variance and the t-statistic ...\n dof = ((var1n1 + var2n2) ** 2) / (((var1n1 ** 2) / REAL(n1 - 1_INT64, kind = REAL64)) + ((var2n2 ** 2) / REAL(n2 - 1_INT64, kind = REAL64)))\n s = SQRT(var1n1 + var2n2)\n t = (mean1 - mean2) / s\n END IF\n\n ! Calculate probability ...\n p = 2.0e0_REAL64 * (1.0e0_REAL64 - func_t_CDF(ABS(t), dof))\nEND SUBROUTINE sub_ttest_ind\n", "meta": {"hexsha": "47ea176d8079cfaf4ff45e86c39510680b8000b5", "size": 3159, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/sub_ttest_ind.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_ttest_ind.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_ttest_ind.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": 50.1428571429, "max_line_length": 148, "alphanum_fraction": 0.462804685, "num_tokens": 804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.956634206181515, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.8277029550675097}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!% \n!% Description:\n!% + Return the natural logarithm of an ndim-dimensional Multivariate Normal (MVN) \n!% probability density function (PDF) with the Mean and Covariance Matrix as defined below.\n!% Reference: https://en.wikipedia.org/wiki/Multivariate_normal_distribution\n!% Input:\n!% + ndim: The number of dimensions of the domain of the objective function.\n!% + point: The input 64-bit real-valued vector of length ndim, \n!% at which the natural logarithm of objective function is computed.\n!% Output:\n!% + logFunc: A 64-bit real scalar number representing the natural logarithm of the objective function.\n!% Author:\n!% + Computational Data Science Lab, Monday 9:03 AM, May 16 2016, ICES, UT Austin\n!% Visit:\n!% + https://www.cdslab.org/paramonte\n!%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nmodule LogFunc_mod\n\n use paramonte, only: IK, RK\n\n implicit none\n\n ! The number of dimensions of the domain of the objective function\n\n integer(IK), parameter :: NDIM = 4_IK\n\n ! The mean vector of the MVN\n\n real(RK), parameter :: MEAN(NDIM) = [0._RK, 0._RK, 0._RK, 0._RK]\n\n ! The coefficient of the Multivariate Normal Distribution: log(1/sqrt(2*Pi)^ndim)\n\n real(RK), parameter :: LOG_INVERSE_SQRT_TWO_PI = log(1._RK/sqrt(2._RK*acos(-1._RK)))\n\n ! The covariance matrix of the MVN\n\n real(RK), parameter :: COVMAT(NDIM,NDIM) = reshape([ 1.0_RK,0.5_RK,0.5_RK,0.5_RK &\n , 0.5_RK,1.0_RK,0.5_RK,0.5_RK &\n , 0.5_RK,0.5_RK,1.0_RK,0.5_RK &\n , 0.5_RK,0.5_RK,0.5_RK,1.0_RK ], shape=shape(COVMAT))\n\n ! The inverse covariance matrix of the MVN\n\n real(RK), parameter :: INVCOVMAT(NDIM,NDIM) = reshape( [ +1.6_RK, -0.4_RK, -0.4_RK, -0.4_RK &\n , -0.4_RK, +1.6_RK, -0.4_RK, -0.4_RK &\n , -0.4_RK, -0.4_RK, +1.6_RK, -0.4_RK &\n , -0.4_RK, -0.4_RK, -0.4_RK, +1.6_RK ], shape=shape(INVCOVMAT))\n\n ! The logarithm of square root of the determinant of the inverse covariance matrix of the Multivariate Normal Distribution \n\n real(RK), parameter :: LOG_SQRT_DET_INV_COV = 0.581575404902840_RK\n\n ! MVN_COEF\n\n real(RK), parameter :: MVN_COEF = NDIM * LOG_INVERSE_SQRT_TWO_PI + LOG_SQRT_DET_INV_COV\n\ncontains\n\n function getLogFunc(ndim,Point) result(logFunc)\n ! Return the negative natural logarithm of MVN distribution evaluated at the input vector point.\n implicit none\n integer(IK), intent(in) :: ndim\n real(RK), intent(in) :: Point(ndim)\n real(RK) :: NormedPoint(ndim)\n real(RK) :: logFunc\n NormedPoint = Point - MEAN\n logFunc = MVN_COEF - 0.5_RK * ( dot_product(NormedPoint,matmul(INVCOVMAT,NormedPoint)) )\n end function getLogFunc\n\nend module LogFunc_mod\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "abb2bc00f03f4dca8d78c5167f997509c3523eca", "size": 3523, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/mvn/Fortran/logfunc.f90", "max_stars_repo_name": "ekourkchi/paramonte", "max_stars_repo_head_hexsha": "15f8ea27cb514078a94d9c4ee4b60e4f45826f17", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 158, "max_stars_repo_stars_event_min_datetime": "2020-01-13T06:40:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T03:12:03.000Z", "max_issues_repo_path": "example/mvn/Fortran/logfunc.f90", "max_issues_repo_name": "ekourkchi/paramonte", "max_issues_repo_head_hexsha": "15f8ea27cb514078a94d9c4ee4b60e4f45826f17", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2020-10-31T22:46:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T19:57:06.000Z", "max_forks_repo_path": "example/mvn/Fortran/logfunc.f90", "max_forks_repo_name": "ekourkchi/paramonte", "max_forks_repo_head_hexsha": "15f8ea27cb514078a94d9c4ee4b60e4f45826f17", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-07-04T23:45:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T06:52:07.000Z", "avg_line_length": 46.3552631579, "max_line_length": 132, "alphanum_fraction": 0.5075219983, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731169394882, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8275751753008602}} {"text": "PROGRAM A9Q2\r\n!--\r\n! This program uses Dijkstra's algorithm to find the smallest route between two cities.\r\n!--\r\nIMPLICIT NONE\r\nINTEGER, DIMENSION(:,:), ALLOCATABLE :: A\r\nINTEGER :: Check, n, i, m, k, len\r\n\r\nPRINT *, \"This Program uses Dijkstra's algorithm to find the smallest path between two 'cities'\"\r\nDO\r\n\tPRINT *, \"Please enter the size of the array A[1:n,1:n] as n: (0 to stop)\"\r\n READ *, n\r\n IF (n .eq. 0) STOP\r\n ALLOCATE(A(n,n), STAT=Check)\r\n IF (Check .eq. 0) THEN\r\n\t\tPRINT *, \"Please enter the data for A:\"\r\n READ *, (A(i,1:n), i=1,n)\r\n PRINT *, \"Now please enter the starting and ending points (m and k respectively)\"\r\n\t\tREAD *, m,k\r\n\t\tlen = ShortestPath(A,n,m,k)\r\n IF (len .ne. -1) THEN\r\n \tPRINT \"(1X, 'The shortest path from', I5, ' to', I5, ' is: ', I5)\", m, k, len\r\n ELSE\r\n \tPRINT \"(1X, 'There exists no path from', I5, ' to', I5)\", m, k\r\n END IF\r\n \tDEALLOCATE(A)\r\n\tELSE \r\n \tPRINT *, \"Allocation unsuccessful, please try again.\"\r\n \tEND IF\r\nEND DO\r\n\r\nCONTAINS\r\nINTEGER FUNCTION ShortestPath(A,n,m,k)\r\nINTEGER, DIMENSION(n,n), INTENT(IN) :: A\r\nINTEGER, INTENT(IN) :: n,m,k\r\nLOGICAL :: different\r\nINTEGER, DIMENSION(n) :: B, Bprev\r\nINTEGER :: i,j,s,min\r\n\r\nPRINT *, \"Calculating... B will be printed at each step.\"\r\nBprev = 0\r\n!- Initilize the array B with the sum of A + 1. B[m] = 0\r\ns = SUM(A) + 1\r\nDO i=1,n\r\n\tB(i) = s\r\nEND DO\r\nB(m) = 0\r\nPRINT *, B\r\n!- now loop through and modify B until B is no longer changed\r\ndifferent = .true.\r\nDO WHILE (different)\r\n Bprev = B\r\n !- For each node,\r\n DO i= 1,n\r\n \tIF (i .ne. m) THEN\r\n !- then find the minimum value\r\n min = s\r\n\t DO j=1,n\r\n \t!- Do not consider node loops or when a node is not connected to another\r\n\t\tIF (j .ne. i .and. A(j,i) .ne. 0) THEN\r\n \t IF (min > B(j) + A(j, i)) THEN\r\n \tmin = B(j) + A(j, i)\r\n END IF\r\n\t\tEND IF\r\n\t END DO\r\n \t !- Then update the node in B\r\n\t B(i) = min\r\n END IF\r\n END DO\r\n PRINT *, B\r\n !- prove that B changed:\r\n different = .false.\r\n DO i = 1,n\r\n IF (B(i) .ne. Bprev(i))different = .true.\r\n END DO\r\nEND DO\r\nIF (B(k) .ne. s) THEN\r\n ShortestPath = B(k)\r\nELSE\r\n ShortestPath = -1\r\nEND IF\r\n\r\nEND FUNCTION ShortestPath\r\nEND PROGRAM A9Q2\r\n", "meta": {"hexsha": "35f7269f295506d340efb72262531c3e4c9ea969", "size": 2346, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 9/A9Q2.f90", "max_stars_repo_name": "Chris-Drury/COMP3731", "max_stars_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 9/A9Q2.f90", "max_issues_repo_name": "Chris-Drury/COMP3731", "max_issues_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 9/A9Q2.f90", "max_forks_repo_name": "Chris-Drury/COMP3731", "max_forks_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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.6, "max_line_length": 97, "alphanum_fraction": 0.552855925, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.8269123674961082}} {"text": "program test_scalar_cholesky\n\n integer, parameter :: r64 = selected_real_kind (14), &\n r32 = selected_real_kind (6)\n integer :: n\n \n integer :: i, j, k\n\n logical :: positive_definite\n\n real (r64), allocatable :: A (:,:), B (:,:), L (:,:)\n\n real start_time, stop_time\n\n read (*, *) n\n\n allocate ( A (1:n, 1:n), B (1:n, 1:n), L (1:n, 1:n) )\n\n ! -------------------------------------------------------------\n ! create a positive definite matrix A by setting A equal to the\n ! matrix-matrix product B B^T. This normal equations matrix is \n ! positive-definite as long as B is full rank.\n ! -------------------------------------------------------------\n\n write (*,*) \"Cholesky Factorization Tests\"\n write (*,*) \" Matrix Dimension: \", n\n write (*,*) \" Block Size : \", 1\n write (*,*) \" Indexing Base : \", 1\n\n call random_number ( harvest = B )\n\n do i = 1, n\n do j = 1, n\n A (i,j) = 0.0\n do k = 1, n\n A (i,j) = A (i,j) + B (i,k) * B (j,k)\n end do\n end do\n end do\n\n ! factorization algorithms overwrite a copy of A, leaving\n ! the factor L in its place\n\n L = A\n\n call cpu_time ( start_time )\n call scalar_outer_product_cholesky ( n, L, positive_definite )\n call cpu_time ( stop_time )\n\n elapsed_time = stop_time - start_time\n write (*,*) \" Cholesky Factorization time: \", elapsed_time\n write (*,*) \" Collective speed in megaflops: \", &\n ( (n**3) / 3.0 ) / ( 1.0E6 * elapsed_time )\n \n if ( positive_definite ) then\n call check_factorization ( n, A, L )\n else\n write (*,*) \"factorization failed for non-positive semi-definite matrix\"\n end if\n\nend program test_scalar_cholesky\n\n\nsubroutine scalar_outer_product_cholesky ( n, A, positive_definite )\n\n integer, parameter :: r64 = selected_real_kind (14), &\n r32 = selected_real_kind (6)\n integer :: n\n real (r64) :: A (1:n, 1:n)\n logical :: positive_definite\n\n integer :: j, k\n\n positive_definite = .true.\n\n do j = 1, n\n\n if ( A (j,j) > 0.0 ) then\n\n A (j,j) = sqrt ( A (j,j) )\n\n A (j+1:n, j) = A (j+1:n, j) / A (j,j)\n\n do k = j+1, n\n A (k:n, k) = A (k:n, k) - A(k:n, j) * A (k, j)\n end do\n\n else\n\n positive_definite = .false.\n exit\n\n end if\n\n end do\n\nend subroutine scalar_outer_product_cholesky\n\nsubroutine check_factorization ( n, A, L )\n\n integer, parameter :: r64 = selected_real_kind (14), &\n r32 = selected_real_kind (6)\n integer :: n\n\n real (r64) :: A (1:n, 1:n), L (1:n, 1:n)\n\n ! -----------------------------------------------------------------------\n ! Check the factorization by forming L L^T and comparing the result to A.\n ! The factorization is successful if the results are within the\n ! point-wise perturbation bounds of Demmel, given as Theorem 10.5 in\n ! Higham's \"Accuracy and Stability of Numerical Algorithms, 2nd Ed.\"\n ! -----------------------------------------------------------------------\n \n real (r64) :: unit_roundoff, gamma_n1\n \n real (r64) :: d (1:n)\n \n real (r64) :: resid, max_ratio\n \n unit_roundoff = 2.0 ** (-53) ! IEEE 64 bit floating point,\n ! also epsilon (unit_roundoff) in Fortran\n \n gamma_n1 = (n * unit_roundoff) / (1.0 - n * unit_roundoff)\n \n max_ratio = 0.0\n \n do i = 1, n\n d (i) = sqrt ( A (i,i) )\n end do\n \n do i = 1, n\n do j = i+1, n\n \n resid = A (i,j) \n do k = 1, min (i,j)\n resid = resid - L (i,k) * L (j,k)\n end do\n resid = abs (resid)\n \n max_ratio = max ( max_ratio, &\n resid * (1 - gamma_n1) / &\n ( gamma_n1 * d (i) * d (j) ) )\n \n end do\n end do\n \n if ( max_ratio <= 1.0 ) then\n write (*,*) \"factorization successful\"\n else\n write (*,*) \"factorization error exceeds bound by ratio:\", max_ratio\n end if\n \nend subroutine check_factorization\n\n", "meta": {"hexsha": "2bfdfb5d6e2a3ea6ff6942ba94b6236977b4e56f", "size": 4151, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/studies/cholesky/jglewis/version2/performance/fortran/scalar_cholesky.f90", "max_stars_repo_name": "jhh67/chapel", "max_stars_repo_head_hexsha": "f041470e9b88b5fc4914c75aa5a37efcb46aa08f", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1602, "max_stars_repo_stars_event_min_datetime": "2015-01-06T11:26:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:17:21.000Z", "max_issues_repo_path": "test/studies/cholesky/jglewis/version2/performance/fortran/scalar_cholesky.f90", "max_issues_repo_name": "jhh67/chapel", "max_issues_repo_head_hexsha": "f041470e9b88b5fc4914c75aa5a37efcb46aa08f", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 11789, "max_issues_repo_issues_event_min_datetime": "2015-01-05T04:50:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:39:19.000Z", "max_forks_repo_path": "test/studies/cholesky/jglewis/version2/performance/fortran/scalar_cholesky.f90", "max_forks_repo_name": "jhh67/chapel", "max_forks_repo_head_hexsha": "f041470e9b88b5fc4914c75aa5a37efcb46aa08f", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 498, "max_forks_repo_forks_event_min_datetime": "2015-01-08T18:58:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:37:45.000Z", "avg_line_length": 26.7806451613, "max_line_length": 80, "alphanum_fraction": 0.4948205252, "num_tokens": 1198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8840392695254318, "lm_q1q2_score": 0.8268830500932408}} {"text": "!---------------------------------------------------------------------------------------------------------------\n! getNormalPdf returns the density function of a standard normal random variable\n double precision function getNormalPdf(x)\n double precision :: x\n \n getNormalPdf = 0.398942280401433D0 * exp(-x * x * 0.5D0) \n !0.398942280401433 = 1/sqrt(2*pi)\n end function\n", "meta": {"hexsha": "ceeb494224d5b1da17e317d27c6a66c9d35490bb", "size": 400, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/getNormalPdf.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/getNormalPdf.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/getNormalPdf.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": 44.4444444444, "max_line_length": 112, "alphanum_fraction": 0.485, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338079816756, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.8265957647972738}} {"text": "! Created by EverLookNeverSee@GitHub on 6/5/20\n! For more information see FCS/img/Exercise_08_c.png\n\n! Solution:\n! Since x = z * (2 ** m) Hence z = x / (2 ** m)\n! We can choose any `m` as long as -1 <= z <= 1\n! Our x = 3 , for which m = 2 and z = 0.75 works.\n! Smaller `m` will give a larger `z` which will give\n! smaller `xi` which will lead to fewer terms necessary\n! for a certain precision.\n\n! I could not have done it without @taless474, @diehlpk and @LKedward\n\nprogram main\n implicit none\n ! xi_sum --> sum of xi elements\n ! previous --> sum of xi elements in previous step\n ! Ea --> approximation error\n ! declaring and initializing variables\n integer :: i = 1\n real :: x = 3.0, m = 2.0, z = 0.75, ln2 = 0.6931472, ln3, xi, xi_sum = 0.0, previous, Ea\n xi = (1 - z) / (1 + z)\n do ! only xi part of formula is infinite and we need to truncate it\n ! Adding up first element of `xi` series -> `xi` itself\n if (i == 1) then\n xi_sum = xi\n i = i + 1\n else ! Calculating and adding up rest of the elements of series\n previous = xi_sum\n xi_sum = xi_sum + (xi **(2 * i - 1) / (2 * i - 1))\n Ea = xi_sum - previous\n ! Exit whenever approximation error is less than 10e-10\n if (Ea < 10e-10) then\n exit\n else ! Keep going to calculate and add up next element of seirs\n i = i + 1\n cycle\n end if\n end if\n end do\n ! calculating final result for ln(x)\n ln3 = m * ln2 - (2 * xi_sum)\n ! printing and comparing results\n print *, \"ln(\", x, \"):\", ln3\n print *, \"ln(\", x, \") --> fortran intrinsic function:\", ALOG(x)\nend program main", "meta": {"hexsha": "4e12233019cb0fc3eb82abd8955f36966e7950c0", "size": 1752, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_08_c.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_c.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_c.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": 38.0869565217, "max_line_length": 92, "alphanum_fraction": 0.5622146119, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.8976952880018481, "lm_q1q2_score": 0.8265885552393653}} {"text": "program example\nimplicit none\nreal :: d\n\nd = haversine(36.12,-86.67,33.94,-118.40) ! BNA to LAX\nprint '(A,F9.4,A)', 'distance: ',d,' km' ! distance: 2887.2600 km\n\ncontains\n\n function to_radian(degree) result(rad)\n ! degrees to radians\n real,intent(in) :: degree\n real, parameter :: deg_to_rad = atan(1.0)/45 ! exploit intrinsic atan to generate pi/180 runtime constant\n real :: rad\n\n rad = degree*deg_to_rad\n end function to_radian\n\n function haversine(deglat1,deglon1,deglat2,deglon2) result (dist)\n ! great circle distance -- adapted from Matlab\n real,intent(in) :: deglat1,deglon1,deglat2,deglon2\n real :: a,c,dist,dlat,dlon,lat1,lat2\n real,parameter :: radius = 6372.8\n\n dlat = to_radian(deglat2-deglat1)\n dlon = to_radian(deglon2-deglon1)\n lat1 = to_radian(deglat1)\n lat2 = to_radian(deglat2)\n a = (sin(dlat/2))**2 + cos(lat1)*cos(lat2)*(sin(dlon/2))**2\n c = 2*asin(sqrt(a))\n dist = radius*c\n end function haversine\n\nend program example\n", "meta": {"hexsha": "87878fde0ecf7966f64ee5e5d3684e6705681961", "size": 1106, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Haversine-formula/Fortran/haversine-formula.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/Haversine-formula/Fortran/haversine-formula.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/Haversine-formula/Fortran/haversine-formula.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.6, "max_line_length": 115, "alphanum_fraction": 0.6084990958, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9744347823646075, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.8262892762151778}} {"text": "C PROGRAM FOR INTERGRATION BY GAUSSIAN QUADRATURE\nC GAURAV RUDRA MALIK R.NO:23\n\tP1(X)=(3003*x**6 - 3465*x**4 + 945*x**2 - 35)/16\n\tF(X)=1/(1+X**2)\n\tDIMENSION Y(8),W(8)\n\tY(1) = -0.96028985\n\tY(2) = -0.79666647\n\tY(3) = -0.52553240 \n\tY(4) = -0.18343464 \n\tDO 1 I=5,8\n\tY(I)=Y(9-I)*(-1)\n1\tCONTINUE\n\tDO 2 I=1,8\n\tA=(1-(Y(I)**2))*(P1(Y(I)**2))\n\tW(I)= 2/A\n2\tCONTINUE\n\tWRITE(*,*)'ENTER THE LOWER AND UPPER LIMITS'\n\tREAD(*,*) A,B\n\tC=(A+B)/2\n\tD=ABS(A-B)/2\n\tS=0.0\n\tDO 3 I=1,8\n\tS=S + W(I)*F(D*Y(I)+C)\n3\tCONTINUE\n\tS=S*D\n\tWRITE(*,*)'THE INTEGRAL IS CALCULATED TO BE:',S\n\tSTOP\n\tEND\n\nResult\n\n ENTER THE LOWER AND UPPER LIMITS\n1\n2\n THE INTEGRAL IS CALCULATED TO BE: .328349978\n\n\n\t\n\n\t\n", "meta": {"hexsha": "43d4cd9736271e7534cb5629b48cdb95cf613638", "size": 663, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Gaussian_Quad.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": "Gaussian_Quad.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": "Gaussian_Quad.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.1707317073, "max_line_length": 49, "alphanum_fraction": 0.5912518854, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541528387692, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.8262796519004755}} {"text": "MODULE my_math\n !\n USE kind\n ! \n CONTAINS\n FUNCTION dot_prod(a,b)\n REAL(KIND=DP) :: dot_prod\n REAL(KIND=DP), DIMENSION(:), INTENT(IN) :: a,b\n dot_prod = SUM(a*b)\n !dot_prod=a(1)*b(1)+a(2)*b(2)+a(3)*b(3)\n ENDFUNCTION dot_prod\n !\n FUNCTION x_prod(a,b)\n REAL(KIND=DP), DIMENSION(3) :: x_prod\n REAL(KIND=DP), DIMENSION(3), INTENT(IN) :: a,b\n x_prod(1)=a(2)*b(3)-a(3)*b(2) \n x_prod(2)=a(3)*b(1)-a(1)*b(3) \n x_prod(3)=a(1)*b(2)-a(2)*b(1) \n ENDFUNCTION x_prod\n !\n FUNCTION mix_prod(a,b,c)\n REAL(KIND=DP) :: mix_prod\n REAL(KIND=DP), DIMENSION(3), INTENT(IN) :: a,b,c\n mix_prod=dot_prod(a,x_prod(b,c))\n ENDFUNCTION mix_prod\n !\n FUNCTION vect_len(a)\n REAL(KIND=DP) :: vect_len\n REAL(KIND=DP), DIMENSION(3), INTENT(IN) :: a\n vect_len = SQRT(SUM(a*a))\n ENDFUNCTION\n !\nENDMODULE my_math\n", "meta": {"hexsha": "a9451c9c45fb48cbc248ba284b7719eb0fd8508a", "size": 901, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/find-2D-crystal/src/my_math.f90", "max_stars_repo_name": "zyoohv/generate-two-dimensional-materials-automatic", "max_stars_repo_head_hexsha": "eb0f9d5ff974c8c8a38ef3e5bd4ba71353f65581", "max_stars_repo_licenses": ["MIT"], "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/find-2D-crystal/src/my_math.f90", "max_issues_repo_name": "zyoohv/generate-two-dimensional-materials-automatic", "max_issues_repo_head_hexsha": "eb0f9d5ff974c8c8a38ef3e5bd4ba71353f65581", "max_issues_repo_licenses": ["MIT"], "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/find-2D-crystal/src/my_math.f90", "max_forks_repo_name": "zyoohv/generate-two-dimensional-materials-automatic", "max_forks_repo_head_hexsha": "eb0f9d5ff974c8c8a38ef3e5bd4ba71353f65581", "max_forks_repo_licenses": ["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.5, "max_line_length": 55, "alphanum_fraction": 0.5538290788, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811631528336, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.8262225721955118}} {"text": "! September 29, 2021\n! Lecture 02\n! Practice: Solve the quadratic equation using a standard formula and try four\n! different inputs for the coefficients...\nprogram quadratic\n implicit none\n integer, parameter :: SP = kind(0.e0)\n integer, parameter :: dP = kind(0.d0)\n integer, parameter :: QP = kind(0.q0)\n integer, parameter :: WP = SP\n real(kind=WP) :: a, b, c, D, x1, x2, zero, tol\n complex(kind=WP) :: zD, z1, z2, z_zero\n character(len=7) :: mode\n\n print *, \"For a quadratic equation a x^2 + b x + c = 0,\"\n print *, \"coefficients a, b, and c are:\"\n read *, a, b, c\n print *, \"Which mode, 'real' or 'complex'?\"\n read *, mode\n\n select case (mode)\n case (\"real\")\n tol = 10.0_WP * epsilon(0.0_WP) ! tolerance = numerical precision x 10\n D = b**2 - 4.0_WP * a * c\n if (D > 0.0_WP) then ! two distinct roots\n x1 = (-b + sqrt(D)) / (2.0_WP * a)\n x2 = (-b - sqrt(D)) / (2.0_WP * a)\n print *, \"1st distinct root is \", x1\n print *, \"2nd distinct root is \", x2\n\n zero = a * x1**2 + b * x1 + c\n print *, \"Test: a x_1^2 + b x_1 + c = \", zero\n zero = a * x2**2 + b * x2 + c\n print *, \"Test: a x_2^2 + b x_2 + c = \", zero\n else if (abs(D) <= tol) then\n x1 = -b / (2.0_WP * a) ! equal roots\n print *, \"One double root is \", x1\n\n zero = a * x1**2 + b * x1 + c\n print *, \"Test: a x_1^2 + b x_1 + c = \", zero\n else ! D < 0.0: no real roots\n print *, \"There are no real roots, D = \", D\n end if\n case (\"complex\")\n zD = b**2 - 4.0_wp * a * c\n z1 = (-b + sqrt(zD)) / (2.0_WP * a)\n z2 = (-b - sqrt(zD)) / (2.0_WP * a)\n print *, \"1st complex root is \", z1\n print *, \"2nd complex root is \", z2\n !print \"(a, 2(1x, f0.8, sp, f0.8, 'i'))\", \"Two complex roots are \", z1, z2\n\n z_zero = a * z1**2 + b * z1 + c\n print *, \"Test: a z_1^2 + b z_1^2 + c = \", z_zero\n z_zero = a * z2**2 + b * z2 + c\n print *, \"Test: a z_2^2 + b z_2^2 + c = \", z_zero\n case default\n stop \"Wrong mode = \" // mode\n end select\nend program quadratic\n", "meta": {"hexsha": "1c7a4760646b33cf75f4a2f4406c2e55fd70e73f", "size": 2211, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_02/quadratic/quadratic.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_02/quadratic/quadratic.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_02/quadratic/quadratic.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": 36.85, "max_line_length": 82, "alphanum_fraction": 0.4907281773, "num_tokens": 779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.8261715270063263}} {"text": "!\n module various_functions_mod\n!\n contains\n!\n subroutine dmatinv3(A,B,ierr)\n !! Performs a direct calculation of the inverse of a 3×3 matrix.\n double precision,dimension(3,3), intent(in) :: A !! Matrix\n double precision,dimension(3,3), intent(out) :: B(3,3) !! Inverse matrix\n integer, intent(out) :: ierr\n double precision :: detinv\n!\n !Integer for error status (0 ... no error, 1 ... singular matrix)\n ierr = 0\n!\n !Calculate the inverse determinant of the matrix\n detinv = (A(1,1)*A(2,2)*A(3,3) - A(1,1)*A(2,3)*A(3,2)&\n - A(1,2)*A(2,1)*A(3,3) + A(1,2)*A(2,3)*A(3,1)&\n + A(1,3)*A(2,1)*A(3,2) - A(1,3)*A(2,2)*A(3,1))\n!\n if(detinv.eq.0.d0) then\n ierr = 1\n B = 0.d0\n print *,\"Error in dmatinv3: Matrix is singular - Inverse matrix doesn't exist.\"\n stop\n endif\n!\n detinv = 1/detinv\n!\n ! Calculate the inverse of the matrix\n B(1,1) = +detinv * (A(2,2)*A(3,3) - A(2,3)*A(3,2))\n B(2,1) = -detinv * (A(2,1)*A(3,3) - A(2,3)*A(3,1))\n B(3,1) = +detinv * (A(2,1)*A(3,2) - A(2,2)*A(3,1))\n B(1,2) = -detinv * (A(1,2)*A(3,3) - A(1,3)*A(3,2))\n B(2,2) = +detinv * (A(1,1)*A(3,3) - A(1,3)*A(3,1))\n B(3,2) = -detinv * (A(1,1)*A(3,2) - A(1,2)*A(3,1))\n B(1,3) = +detinv * (A(1,2)*A(2,3) - A(1,3)*A(2,2))\n B(2,3) = -detinv * (A(1,1)*A(2,3) - A(1,3)*A(2,1))\n B(3,3) = +detinv * (A(1,1)*A(2,2) - A(1,2)*A(2,1))\n end subroutine\n!\n end module various_functions_mod\n!\n!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n!\n", "meta": {"hexsha": "02ecf8675ff3aa4f8b461d7eee3daee88ab5a89e", "size": 1697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/various_functions_mod.f90", "max_stars_repo_name": "micheder/GORILLA_fork", "max_stars_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "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/various_functions_mod.f90", "max_issues_repo_name": "micheder/GORILLA_fork", "max_issues_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-04-25T20:38:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-12T10:24:15.000Z", "max_forks_repo_path": "SRC/various_functions_mod.f90", "max_forks_repo_name": "micheder/GORILLA_fork", "max_forks_repo_head_hexsha": "78c01af79229c9dcae17e4aa4b7c66f60ac8730b", "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": 36.8913043478, "max_line_length": 90, "alphanum_fraction": 0.4902769593, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960951703918909, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8260953441223161}} {"text": "SUBROUTINE kepler_eq (M, ec, E)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: kepler_eq.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Kepler's Equation solution based on Newton method\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - M:\t\t\tMean amomaly (degrees)\r\n! - ec:\t\t\tEccentricity\r\n!\r\n! Output arguments:\r\n! - E: \tEccentric anomaly (degrees)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 29 August 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_q), INTENT(IN) :: M, ec\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: E\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: Mrad, Eo, f_E\r\n REAL (KIND = prec_q) :: E_arr(8)\r\n INTEGER (KIND = prec_int8) :: Niter, i, sz1\t \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n\r\n! converse in radians\r\nMrad = M * (PI_global /180.D0)\r\n\r\n! ----------------------------------------------------------------------\r\n! Initial approximate value of Eccentric anomaly (E)\r\n! - small eccentricity:\t\t\tEo = M\r\n! - high eccentricity (e>0.8):\tEo = pi\r\nif (e < 0.8D0) then \r\n if (Mrad == 0.D0) then \r\n Eo = Mrad + 0.001D0\r\n else\r\n Eo = Mrad\r\n end if \r\nelse \r\n Eo = PI_global \r\nend if\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! number of iterations\r\nNiter = 7\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Newton method: Iterative solution\r\nDo i = 1 , Niter\r\n\r\n if (i == 1) then \r\n E_arr(i) = Eo\r\n end if \r\n\t\r\n ! auxiliary function\r\n f_E = E_arr(i) - ec * sin( E_arr(i) ) - Mrad\r\n \r\n E_arr(i+1) = E_arr(i) - f_E / ( 1.D0 - ec * cos( E_arr(i) ) )\r\n\t\r\nEnd Do\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Converse in degrees\r\nE_arr = E_arr * (180.D0 / PI_global)\r\n\r\n\r\n! Solution from the final iteration value\r\nsz1 = size(E_arr, DIM = 1)\r\n\r\nE = E_arr(sz1)\r\n\r\n\r\n\r\nEnd\r\n\r\n\r\n", "meta": {"hexsha": "4e1f5e5d6cd502a6ae225521a8e68fc8713458bf", "size": 2848, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/kepler_eq.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/kepler_eq.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/kepler_eq.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": 28.48, "max_line_length": 73, "alphanum_fraction": 0.3156601124, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.8887587993853654, "lm_q1q2_score": 0.826048330444641}} {"text": "Module mo_cost\n\n use mo_kind, only: sp, dp\n\n IMPLICIT NONE\n\n PRIVATE\n\n PUBLIC :: cost_sp, cost_dp\n PUBLIC :: cost_valid_sp, cost_valid_dp\n PUBLIC :: range_sp, range_dp\n\nCONTAINS\n\n FUNCTION cost_sp (paraset)\n\n implicit none\n\n REAL(SP), DIMENSION(:), INTENT(IN) :: paraset\n REAL(SP) :: cost_sp\n REAL(SP), DIMENSION(6,2) :: meas\n REAL(SP), DIMENSION(6) :: calc\n\n ! function: f(x) = ax^3 + bx^2 + cx + d\n ! measurements: (0.5,5.725), (1.0, 21.7), (1.5, 49.175), (2.0, 88.9), (2.5, 141.625), (3.0, 208.1)\n ! --> a=1.0, b=20.0, c=0.2, d=0.5\n\n meas(:,1) = (/0.5_sp, 1.0_sp, 1.5_sp, 2.0_sp, 2.5_sp, 3.0_sp/)\n meas(:,2) = (/5.7250_sp, 21.7000_sp, 49.1750_sp, 88.9000_sp, 141.6250_sp, 208.1000_sp/)\n\n calc(:) = paraset(1)*meas(:,1)**3+paraset(2)*meas(:,1)**2+paraset(3)*meas(:,1)+paraset(4)\n\n ! MAE Mean Absolute Error\n cost_sp = sum(abs( meas(:,2)-calc(:) ))/size(meas,1)\n\n RETURN\n END FUNCTION cost_sp\n\n FUNCTION cost_dp (paraset)\n\n implicit none\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: paraset\n REAL(DP) :: cost_dp\n REAL(DP), DIMENSION(6,2) :: meas\n REAL(DP), DIMENSION(6) :: calc\n\n ! function: f(x) = ax^3 + bx^2 + cx + d\n ! measurements: (0.5,5.725), (1.0, 21.7), (1.5, 49.175), (2.0, 88.9), (2.5, 141.625), (3.0, 208.1)\n ! --> a=1.0, b=20.0, c=0.2, d=0.5\n\n meas(:,1) = (/0.5_dp, 1.0_dp, 1.5_dp, 2.0_dp, 2.5_dp, 3.0_dp/)\n meas(:,2) = (/5.7250_dp, 21.7000_dp, 49.1750_dp, 88.9000_dp, 141.6250_dp, 208.1000_dp/)\n\n calc(:) = paraset(1)*meas(:,1)**3+paraset(2)*meas(:,1)**2+paraset(3)*meas(:,1)+paraset(4)\n\n ! MAE Mean Absolute Error\n cost_dp = sum(abs( meas(:,2)-calc(:) ))/size(meas,1)\n\n RETURN\n END FUNCTION cost_dp\n\n FUNCTION cost_valid_sp (paraset,status_in)\n\n implicit none\n\n REAL(SP), DIMENSION(:), INTENT(IN) :: paraset\n LOGICAL, OPTIONAL, INTENT(OUT) :: status_in\n REAL(SP) :: cost_valid_sp\n REAL(SP), DIMENSION(6,2) :: meas\n REAL(SP), DIMENSION(6) :: calc\n\n ! function: f(x) = ax^3 + bx^2 + cx + d\n ! measurements: (0.5,5.725), (1.0, 21.7), (1.5, 49.175), (2.0, 88.9), (2.5, 141.625), (3.0, 208.1)\n ! --> a=1.0, b=20.0, c=0.2, d=0.5\n\n meas(:,1) = (/0.5_sp, 1.0_sp, 1.5_sp, 2.0_sp, 2.5_sp, 3.0_sp/)\n meas(:,2) = (/5.7250_sp, 21.7000_sp, 49.1750_sp, 88.9000_sp, 141.6250_sp, 208.1000_sp/)\n\n calc(:) = paraset(1)*meas(:,1)**3+paraset(2)*meas(:,1)**2+paraset(3)*meas(:,1)+paraset(4)\n\n if (present(status_in)) then\n status_in = .true.\n ! Define a status .false. if calculation of \"calc\" was not successful \n end if\n\n ! MAE Mean Absolute Error\n cost_valid_sp = sum(abs( meas(:,2)-calc(:) ))/size(meas,1)\n\n RETURN\n END FUNCTION cost_valid_sp\n\n FUNCTION cost_valid_dp (paraset,status_in)\n\n implicit none\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: paraset\n LOGICAL, OPTIONAL, INTENT(OUT) :: status_in\n REAL(DP) :: cost_valid_dp\n REAL(DP), DIMENSION(6,2) :: meas\n REAL(DP), DIMENSION(6) :: calc\n\n ! function: f(x) = ax^3 + bx^2 + cx + d\n ! measurements: (0.5,5.725), (1.0, 21.7), (1.5, 49.175), (2.0, 88.9), (2.5, 141.625), (3.0, 208.1)\n ! --> a=1.0, b=20.0, c=0.2, d=0.5\n\n meas(:,1) = (/0.5_dp, 1.0_dp, 1.5_dp, 2.0_dp, 2.5_dp, 3.0_dp/)\n meas(:,2) = (/5.7250_dp, 21.7000_dp, 49.1750_dp, 88.9000_dp, 141.6250_dp, 208.1000_dp/)\n\n calc(:) = paraset(1)*meas(:,1)**3+paraset(2)*meas(:,1)**2+paraset(3)*meas(:,1)+paraset(4)\n\n if (present(status_in)) then\n status_in = .true.\n ! Define a status .false. if calculation of \"calc\" was not successful \n end if\n\n ! MAE Mean Absolute Error\n cost_valid_dp = sum(abs( meas(:,2)-calc(:) ))/size(meas,1)\n\n RETURN\n END FUNCTION cost_valid_dp\n\n SUBROUTINE range_dp(paraset, iPar, rangePar)\n use mo_kind\n REAL(DP), DIMENSION(:), INTENT(IN) :: paraset\n INTEGER(I4), INTENT(IN) :: iPar\n REAL(DP), DIMENSION(2), INTENT(OUT) :: rangePar\n\n ! Range does not depend on parameter set\n ! select case(iPar)\n ! case(1_i4)\n ! rangePar(1) = 0.0_dp\n ! rangePar(2) = 10.0_dp\n ! case(2_i4)\n ! rangePar(1) = 0.0_dp\n ! rangePar(2) = 40.0_dp\n ! case(3_i4)\n ! rangePar(1) = 0.0_dp\n ! rangePar(2) = 10.0_dp\n ! case(4_i4)\n ! rangePar(1) = 0.0_dp\n ! rangePar(2) = 5.0_dp\n ! end select\n\n ! Range of parameter 2 depends on value of parameter 1: \n ! parameter 2 at most 40* parameter 1 : \n ! 0 <= p2 <= 40p1\n ! 0 <= p1 <= 0.025p2\n select case(iPar)\n case(1_i4)\n rangePar(1) = 0.025_dp*paraset(2) \n rangePar(2) = 10.0_dp \n case(2_i4)\n rangePar(1) = 0.0_dp\n rangePar(2) = 40.0_dp*paraset(1)\n case(3_i4)\n rangePar(1) = 0.0_dp\n rangePar(2) = 10.0_dp\n case(4_i4)\n rangePar(1) = 0.0_dp\n rangePar(2) = 5.0_dp\n end select\n\n END SUBROUTINE range_dp\n\n SUBROUTINE range_sp(paraset, iPar, rangePar)\n use mo_kind\n REAL(SP), DIMENSION(:), INTENT(IN) :: paraset\n INTEGER(I4), INTENT(IN) :: iPar\n REAL(SP), DIMENSION(2), INTENT(OUT) :: rangePar\n\n ! Range does not depend on parameter set\n ! select case(iPar)\n ! case(1_i4)\n ! rangePar(1) = 0.0_sp\n ! rangePar(2) = 10.0_sp\n ! case(2_i4)\n ! rangePar(1) = 0.0_sp\n ! rangePar(2) = 40.0_sp\n ! case(3_i4)\n ! rangePar(1) = 0.0_sp\n ! rangePar(2) = 10.0_sp\n ! case(4_i4)\n ! rangePar(1) = 0.0_sp\n ! rangePar(2) = 5.0_sp\n ! end select\n\n ! Range of parameter 2 depends on value of parameter 1: \n ! parameter 2 at most 4* parameter 1 : \n ! 0 <= p2 <= 4p1\n ! 0.25p2 <= p1 <= 10.0\n select case(iPar)\n case(1_i4)\n rangePar(1) = 0.025_sp*paraset(2)\n rangePar(2) = 10.0_sp\n case(2_i4)\n rangePar(1) = 0.0_sp\n rangePar(2) = 40.0_sp*paraset(1)\n case(3_i4)\n rangePar(1) = 0.0_sp\n rangePar(2) = 10.0_sp\n case(4_i4)\n rangePar(1) = 0.0_sp\n rangePar(2) = 5.0_sp\n end select\n\n END SUBROUTINE range_sp\n\nEND MODULE mo_cost\n", "meta": {"hexsha": "566d6d7b8d05afea61e403eeb67b58aba76534bb", "size": 6345, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_anneal/mo_cost.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_anneal/mo_cost.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_anneal/mo_cost.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": 30.2142857143, "max_line_length": 102, "alphanum_fraction": 0.5375886525, "num_tokens": 2565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.8260420258803329}} {"text": "function chebpts(n,I_in) result(c)\n! Returns chebyshev points on interval I\n! === Parameters ===\n! n - number of chebyshev points\n! I - (array) 2x1 array containing inteval\n! === Output ===\n! c - (array) nx1 array of chebyshev points\ninteger, intent(in) :: n\nreal(kind=8), intent(in), optional :: I_in(2)\nreal(kind=8) :: c(n), m, a, I(2)\ninteger :: j\nif(present(I_in)) then\n I = I_in\nelse\n I = (/ -1.d0, 1.d0 /)\nendif\n\nm = (I(2) + I(1))/2.d0\na = (I(2) - I(1))/2.d0\ndo j=1,n\n c(j) = -1.d0 * a * cos((j-1.d0)*PI/(n-1.d0)) + m\nenddo\nend function chebpts", "meta": {"hexsha": "c36c51588a79809159a0a8c1f008ee51f6df9ccc", "size": 559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/chebpts.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/chebpts.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/chebpts.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.3043478261, "max_line_length": 52, "alphanum_fraction": 0.595706619, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341987633822, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.8259499376636477}} {"text": "MODULE Simulation\n\n IMPLICIT NONE\n\n CONTAINS\n\n FUNCTION Pi(samples)\n REAL :: Pi\n REAL :: coords(2), length\n INTEGER :: i, in_circle, samples\n\n in_circle = 0\n DO i=1, samples\n CALL RANDOM_NUMBER(coords)\n coords = coords * 2 - 1\n length = SQRT(coords(1)*coords(1) + coords(2)*coords(2))\n IF (length <= 1) in_circle = in_circle + 1\n END DO\n Pi = 4.0 * REAL(in_circle) / REAL(samples)\n END FUNCTION Pi\n\nEND MODULE Simulation\n\nPROGRAM MONTE_CARLO\n\n USE Simulation \n\n INTEGER :: n = 1000000000\n WRITE (*,*) 'pi: ', Pi(n)\n\nEND PROGRAM MONTE_CARLO", "meta": {"hexsha": "655c8f4cecf42a389b855032aee4d04dd680b0f1", "size": 587, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "monte_carlo.f95", "max_stars_repo_name": "pnadon/monte-carlo-comparison", "max_stars_repo_head_hexsha": "ce5227ee1ffba54855d1e236c1379f2204c17a6b", "max_stars_repo_licenses": ["MIT"], "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.f95", "max_issues_repo_name": "pnadon/monte-carlo-comparison", "max_issues_repo_head_hexsha": "ce5227ee1ffba54855d1e236c1379f2204c17a6b", "max_issues_repo_licenses": ["MIT"], "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.f95", "max_forks_repo_name": "pnadon/monte-carlo-comparison", "max_forks_repo_head_hexsha": "ce5227ee1ffba54855d1e236c1379f2204c17a6b", "max_forks_repo_licenses": ["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.935483871, "max_line_length": 62, "alphanum_fraction": 0.6286201022, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079105, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.8259158397595888}} {"text": "!**********************************************************************\n! pi3f90.f - compute pi by integrating f(x) = 4/(1 + x**2) \n!\n! (C) 2001 by Argonne National Laboratory.\n! modified by Thomas Hauser\n! \n! Each node: \n! 1) receives the number of rectangles used in the approximation.\n! 2) calculates the areas of it's rectangles.\n! 3) Synchronizes for a global summation.\n! Node 0 prints the result.\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 pi_mpi\n\n USE mpi\n\n INTEGER, parameter :: dp = kind(1.0d0)\n REAL(dp):: PI25DT = 3.141592653589793238462643d0\n\n REAL(dp) :: mypi, pi, h, sum, x, f, a\n INTEGER :: n, myid, numprocs, i, rc\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 PRINT *, 'Process ', myid, ' of ', numprocs, ' is alive'\n\n sizetype = 1\n sumtype = 2\n\n IF ( myid .EQ. 0 ) THEN\n WRITE(6,98)\n98 FORMAT('Enter the number of intervals:')\n READ(5,99) n\n99 FORMAT(i10)\n ENDIF\n\n CALL MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)\n\n ! check for quit signal\n\n ! calculate the interval size\n h = 1.0d0/n\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\n ! collect all the partial sums\n CALL MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0, &\n MPI_COMM_WORLD,ierr)\n\n ! node 0 prints the answer.\n IF (myid .EQ. 0) THEN\n WRITE(6, 97) pi, ABS(pi - PI25DT)\n97 FORMAT(' pi is approximately: ', F18.16, &\n ' Error is: ', F18.16)\n ENDIF\n\n\n CALL MPI_FINALIZE(rc)\nEND PROGRAM pi_mpi\n\n\n\n\n", "meta": {"hexsha": "b50e5f670ef74adc8b4474e737fa22e16c16e636", "size": 2208, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lab/Pi_f/pi_mpi.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": "MPI/Lab/Pi_f/pi_mpi.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": "MPI/Lab/Pi_f/pi_mpi.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": 26.9268292683, "max_line_length": 77, "alphanum_fraction": 0.5330615942, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.8991213833519948, "lm_q1q2_score": 0.825825235614785}} {"text": "MODULE m_lagrange\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! MODULE: m_lagrange.f03\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Module for calling the subroutine 'interp_lag' for Lagrange interpolation\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\t13 November 2017\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n IMPLICIT NONE\r\n !SAVE \t\t\t\r\n\t \r\n\r\n\r\nContains\r\n\r\nSUBROUTINE interp_lag (Xint, X_interp, Y_interp, Yint)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: interp_lag\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Interpolation based on Lagrange polynomials\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - Xint: \t\t\tX value where the interpolated value of Y is required\r\n! - X_interp: \tarray of values of the independent variable X\r\n! - Y_interp: \tarray of the Y function values corresponding to X i.e. y=f(x)\r\n!\r\n! Output arguments:\r\n! - Yint:\t\t\tY interpolated value at Xint\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\t5 August 2016\r\n! ----------------------------------------------------------------------\r\n! Last modified:\r\n! - Dr. Thomas Papanikolaou, 14 November 2017:\r\n!\tUpgraded from Fortran 90 to Fortran 2003 for considering the\r\n!\tFortran 2003 adavantages in dynamic memory allocation\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n !USE mdl_arr\r\n IMPLICIT NONE\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n REAL (KIND = prec_q), INTENT(IN) :: Xint\r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(:), ALLOCATABLE :: X_interp \r\n REAL (KIND = prec_q), INTENT(IN), DIMENSION(:), ALLOCATABLE :: Y_interp \r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: Yint\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n INTEGER (KIND = prec_int4) :: sz1, n, i, j\r\n REAL (KIND = prec_q) :: L_numerator, L_denominator, Li\r\n REAL (KIND = prec_q), DIMENSION(:), ALLOCATABLE :: L \r\n INTEGER (KIND = prec_int2) :: AllocateStatus, DeAllocateStatus\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n \r\n! Number of Data points\r\nn = size(X_interp, DIM = 1)\r\n\r\n!sz1 = size(Y_interp, DIM = 1)\r\n!print *,'n,sz1', n, sz1\r\n\r\n\r\nAllocate( L(n), STAT = AllocateStatus)\r\n!print *, \"AllocateStatus=\", AllocateStatus\r\nif (AllocateStatus == 0) then\r\n\r\n! Computation of coefficients Li (xint)\r\nDO i = 1 , n\r\n L_numerator = 1.0D0 \r\n L_denominator = 1.0D0\r\n \r\n DO j = 1 , n\r\n\t If (j == i) then\r\n\t ! not\r\n\t Else\r\n\t\tL_numerator = ( xint - X_interp(j) ) * L_numerator \r\n L_denominator = ( X_interp(i) - X_interp(j) ) * L_denominator\r\n\t End If\r\n\tEnd Do\r\n\r\n L(i) = L_numerator / L_denominator\r\n\t!Li = L_numerator / L_denominator\r\n !L(i) = Li\r\nEnd Do\r\n\r\n!print *,\"X_interp\", X_interp\r\n!print *,\"L\", L\r\n\r\n\r\n! Value of function Y(X) at the point xint\r\n! Value is approximated by interpolant Pn(xint) based on Lagrange Polynomial\r\nyint = 0.D0\r\n\r\nDo i = 1 , n\r\n yint = Y_interp(i) * L(i) + yint\r\nEnd Do\r\n\r\n\r\nDeallocate(L, STAT = DeAllocateStatus)\r\nelse\r\n ! only hit if the allocation fails\r\n yint = 1.d0\r\nend if\r\n\r\n\r\n!print *,\"yint\",yint\r\n\r\n\r\nEnd subroutine\r\n\r\n\r\n\r\nEnd Module\r\n\r\n\r\n", "meta": {"hexsha": "75b3a32561d554777bd7e28d291f9d44bce39b0b", "size": 4053, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/m_lagrange.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_lagrange.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_lagrange.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": 29.8014705882, "max_line_length": 99, "alphanum_fraction": 0.4564520109, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.8723473730188543, "lm_q1q2_score": 0.8257611185575181}} {"text": "! Objetivo: Reproduzir o grafico do periodo em funcao do angulo inicial\n\nMODULE pendulo\n!Dados globais\n REAL :: k\nCONTAINS\n FUNCTION func_integral_elip(xi)\n IMPLICIT none\n REAL, DIMENSION (:), INTENT(in) :: xi\n REAL, DIMENSION(SIZE(xi)) :: func_integral_elip\n func_integral_elip = 1./sqrt(1.-(k*sin(xi))**2)\n END FUNCTION func_integral_elip\nEND MODULE pendulo\n\nPROGRAM pendulo_simples\n\n USE pendulo\n USE nrtype\n USE nrutil\n USE nr, ONLY: qromb, trapzd, polint\n\n IMPLICIT none\n REAL :: theta, integral\n INTEGER :: n_repeticoes\n REAL, PARAMETER :: theta_inicial = 0., theta_final = pi\n INTEGER, PARAMETER :: n_pontos = 1000, dados_pendulo = 8\n REAL, PARAMETER :: n_pontos_real = REAL(n_pontos)\n REAL, PARAMETER :: incremento = (theta_final-theta_inicial)/n_pontos_real\n REAL, PARAMETER :: intervalo_a = 0., intervalo_b = pio2\n\n OPEN(dados_pendulo,file=\"dados_pendulo.dat\")\n theta = theta_inicial\n DO n_repeticoes = 1, n_pontos\n k=sin(0.5*theta)\n!Calcular a integral no intervalo de 0 a pi/2\n integral = qromb( func_integral_elip, intervalo_a, intervalo_b )\n WRITE(dados_pendulo, *) theta/pi, integral/pio2\n theta = theta +incremento\n END DO\n CLOSE(dados_pendulo)\n\nEND PROGRAM pendulo_simples\n", "meta": {"hexsha": "c1acb90c5b88cb6a0fedcfb07a525d1d3b2b41c8", "size": 1270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Monte_Carlo/pendulo.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/pendulo.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/pendulo.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": 29.5348837209, "max_line_length": 76, "alphanum_fraction": 0.7070866142, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8254607508958867}} {"text": "* Home work #2\r\n* Question (2)\r\n* write a Fortran program to find the numerical integration\r\n* of the following function and find error:\r\n\r\n* (iii) f(x)=1/sqrt((1-x^2)) from (-1,1)\r\n\r\n func(x)=1/sqrt((1-x**2))\r\n write(*,*)'f(x)=1/(1-x^2)^0.5'\r\n write(*,*)'exact integral(f(x)) =sin-1(x)'\r\n write(*,*)'Enter Number of parts (Must be even)'\r\n Read(*,*)n\r\n if(n.LT.2) stop\r\n if(mod(n,2).ne.0) n=n+1\r\n write(*,*)'Enter the initial value of integration interval'\r\n read(*,*)Xi\r\n write(*,*)'Enter the final value of integration interval'\r\n read(*,*)Xf\r\n exact=asin(xf)-asin(xi)\r\n h=(Xf-Xi)/n\r\n x=xi\r\n sum=0.0\r\n\r\n Do 10 I=1,N-1\r\n sum=sum+func(x)\r\n10 x=x+h\r\n rectangles=sum*h\r\n trapazodial=0.5*h*(func(xi)+2.0*sum+func(xf))\r\n Simp=(3*h/8)*(func(xi)+3*func(xi+h)+3*func(xi+2*h)+func(xi+3*h))\r\n Bode=7*func(xi)+7*func(xi+4*h)+12*func(xi+2*h)\r\n Bode=(2*h/45)*(bode+32*func(xi+h)+32*func(xi+3*h))\r\n error_rectangles=abs(abs(exact)-rectangles)\r\n error_trapazodial=abs(abs(exact)-trapazodial)\r\n error_Simp=abs(abs(exact)-Simp)\r\n error_Bode=abs(abs(exact)-Bode)\r\n20 format(4f 12.4)\r\n write(*,*)' Xi=',xi\r\n write(*,*)'Xf=',xf\r\n write(*,*)'H=',h\r\n write(*,*) ' '\r\n write(*,*)' Exact Numerical- '\r\n write(*,*)' Integral Integral error '\r\n write(*,*)'------------*------------*------------'\r\n write(*,20)exact ,rectangles ,error_rectangles\r\n write(*,20)exact ,trapazodial ,error_trapazodial\r\n write(*,20)exact ,Simp ,error_Simp\r\n write(*,20)exact ,Bode ,error_Bode\r\n\r\n end\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "0f16db1b71a33e5a8d39050608a6d9f4e21269ba", "size": 1796, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW(2)/Problem(2)/Problem(2)(iii)/Problem_2_iii_.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(2)/Problem(2)(iii)/Problem_2_iii_.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(2)/Problem(2)(iii)/Problem_2_iii_.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": 32.0714285714, "max_line_length": 73, "alphanum_fraction": 0.4927616927, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.8252834905609147}} {"text": "function gauss_sparse(num_iter, tol, b, A, x, actual_iter) result(tol_max)\n\n! This function solves a system of equations (Ax = b) by using the Gauss-Seidel Method\n\n implicit none\n\n real :: tol_max\n\n! Input: its value cannot be modified from within the function\n integer, intent(in) :: num_iter\n real, intent(in) :: tol\n real, intent(in), dimension(:) :: b, A(:,:)\n\n! Input/Output: its input value is used within the function, and can be modified\n real, intent(inout) :: x(:)\n\n! Output: its value is modified from within the function, only if the argument is required\n integer, optional, intent(out) :: actual_iter\n\n! Locals\n integer :: i, n, iter\n real :: xk\n\n! Initialize values\n n = size(b) ! Size of array, obtained using size intrinsic function\n tol_max = 2. * tol\n iter = 0\n\n! Compute solution until convergence\n convergence_loop: do while (tol_max >= tol .and. iter < num_iter); iter = iter + 1\n\n tol_max = -1. ! Reset the tolerance value\n\n! Compute solution for the k-th iteration\n iteration_loop: do i = 1, n\n\n! Compute the current x-value\n xk = (b(i) - dot_product(A(i,:i-1),x(:i-1)) - dot_product(A(i,i+1:n),x(i+1:n))) / A(i, i)\n\n! Compute the error of the solution\n! dot_product(a,v)=a'b\n tol_max = max((abs(x(i) - xk)/(1. + abs(xk))) ** 2, abs(A(i, i) * (x(i) - xk)), tol_max)\n x(i) = xk\n enddo iteration_loop\n enddo convergence_loop\n\n if (present(actual_iter)) actual_iter = iter\n\nend function gauss_sparse", "meta": {"hexsha": "7696afd1637021cf31392c326e92337643e2b196", "size": 1523, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/data/Fortran-90/gauss.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-90/gauss.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-90/gauss.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": 31.0816326531, "max_line_length": 98, "alphanum_fraction": 0.6408404465, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8840392725805822, "lm_q1q2_score": 0.8251894984610345}} {"text": "module num_diff\n use nrtype\n use nrtools, only : rcsv_bicoef\ncontains\n function sifodi1(func,x,h)\n ! si := simple, fo := forward, di1 = 1st derivative\n implicit none\n real(dp), intent(in) :: x, h ! Variable and step size.\n real(dp) :: sifodi1\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n div0: if (h == 0) then\n write(*,*) ' Error: sifodi1:: Division by zero.'\n return\n end if div0\n sifodi1 = (func(x+h) - func(x))/h\n end function sifodi1\n\n function eicedi1(func,x,h)\n ! ei := eigth order, ce := central, di1 := 1st derivative\n implicit none\n real(dp), intent(in) :: x, h ! Variable and step size.\n real(dp) :: eicedi1\n real(dp) :: ho8, ho8p6 ! h/8\n real(dp), parameter :: c4 = 1./280, c3 = 4./105, c2 = 0.2, c1 = 0.8\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n ho8 = 0.125_dp*h\n ho8p6 = ho8**6._dp\n\n div0: if (ho8p6 == 0) then\n write(*,*) ' Error: eicedi1 :: Division by zero.'\n return\n end if div0\n eicedi1 = (c4*func(x-ho8*4._dp)-c3*func(x-ho8*3._dp)+c2*func(x-ho8*2._dp)&\n -c1*func(x-ho8)&\n +c1*func(x+ho8)&\n -c4*func(x+ho8*4._dp)+c3*func(x+ho8*3._dp)-c2*func(x+ho8*2._dp))/ho8p6\n end function eicedi1\n\n function dncoef1(n)\n ! Coefficients for n'th order derivatives with 1st order errors for forward and backward differences, 2nd order errors for central differences\n ! https://en.wikipedia.org/wiki/Finite_difference\n implicit none\n integer, intent(in) :: n\n real(dp) :: dncoef1(n+1)\n integer :: i\n\n ! Calculate the Coefficients.\n cc: do i = 0, n\n dncoef1(n+1-i) = (-1)**i * rcsv_bicoef(n,i)\n end do cc\n end function dncoef1\n\n function dncoefn(n, k, grid, xi) result(coefnk)\n ! n = order of the derivative.\n ! k = number of grid points (h-steps)\n ! xi\n ! rdncoefn = array of coefficients of nth order with k - n + 1 order of accuracy\n ! http://www.ams.org/journals/mcom/1988-51-184/S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf\n implicit none\n integer, intent(in) :: n, k\n real(dp), intent(in) :: xi, grid(0:k)\n integer :: sk, nu, sn\n real(dp) :: c1, c2, c3\n real(dp) :: coefnk(0:n,0:k,0:k)\n\n ! Check for parameter errors.\n\n coefnk = 0._dp\n coefnk(0,0,0) = 1._dp\n c1 = 1._dp\n\n ! Loop Over Derivatives.\n od: do sk = 1, k\n\n c2 = 1._dp\n\n ! Loop Over H-Steps.\n ohs: do nu = 0, sk - 1\n c3 = grid(sk) - grid(nu)\n c2 = c2 * c3\n\n ! Inner loop Over Derivatives.\n iod: do sn = 0, minval([sk, n])\n ! Prevent Memory Dump\n pmd1: if( sn /= 0 ) then\n coefnk(sn, sk, nu) = ( grid(sk) - xi ) * coefnk(sn,sk-1,nu) - sn * coefnk(sn-1,sk-1,nu)\n else pmd1\n coefnk(sn, sk, nu) = ( grid(sk) - xi ) * coefnk(sn,sk-1,nu)\n end if pmd1\n coefnk(sn, sk, nu) = coefnk(sn, sk, nu) / c3\n end do iod\n end do ohs\n\n ! loop over derivatives\n do sn = 0, minval([sk,n])\n pmd2: if ( sn /= 0 ) then\n coefnk(sn, sk, sk) = c1/c2 * ( sn * coefnk(sn-1,sk-1,sk-1) - (grid(sk-1) - xi) * coefnk(sn,sk-1,sk-1) )\n else pmd2\n coefnk(sn, sk, sk) = -c1/c2 * (grid(sk-1) - xi) * coefnk(sn,sk-1,sk-1)\n end if pmd2\n end do\n c1 = c2\n end do od\n end function dncoefn\n\n function ndifnk(func, x, h, n, grid, coefn)\n ! forward/backward numerical differentiator for n'th derivatives with k'th order errors\n implicit none\n real(dp), intent(in) :: x, h, grid(:), coefn(:)\n integer, intent(in) :: n\n real(dp) :: ndifnk\n integer :: i, m\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n ! Size of grid and coefn\n ! Check Size.\n check_size: if ( size(grid) == size(coefn) ) then\n ! Asign m to the size of the array.\n m = size(grid)\n else check_size\n write(*,*) \" Error: num_diff: fdon: check_size: size(grid) must be equal to size(coefn); &\n size(grid) = \", size(grid), \" size(coefn) = \", size(coefn)\n return\n end if check_size\n\n ! Set fdon to 0.\n ndifnk = 0._dp\n\n ! Construct Derivative.\n cd: do i = 1, m\n ndifnk = ndifnk + coefn(i) * func( x + h * grid(i) )/h**n\n end do cd\n end function ndifnk\n\n function fdo1(func, x, h, coef1)\n ! forward numerical differentiator for n'th derivative with first order errors\n implicit none\n real(dp), intent(in) :: x, h\n integer, intent(in) :: coef1(:)\n real(dp) :: fdo1\n integer :: i, n\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n fdo1 = 0._dp\n ! Size of the coefficient array.\n n = size(coef1)-1\n ! Calculate Derivative with .\n cd: do i = 0, n\n fdo1 = fdo1 + coef1(i+1) * func( x - (n-i)*h )\n end do cd\n fdo1 = fdo1/h**n\n end function fdo1\n\n function bdo1(func, x, h, coef1)\n ! backward numerical differentiator for n'th derivative with first order errors\n implicit none\n real(dp), intent(in) :: x, h\n integer, intent(in) :: coef1(:)\n real(dp) :: bdo1\n integer :: i, n\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n bdo1 = 0._dp\n ! Size of the coefficient array.\n n = size(coef1)-1\n ! Calculate Derivative with .\n cd: do i = 0, n\n bdo1 = bdo1 + coef1(n-i+1) * func( x - i*h )\n end do cd\n bdo1 = bdo1/h**n\n end function bdo1\n\n function cdo1(func, x, h, coef1)\n ! central numerical differentiator for n'th derivatives with first order errors\n implicit none\n real(dp), intent(in) :: x, h\n integer, intent(in) :: coef1(:)\n real(dp) :: cdo1\n integer :: i, n\n interface functn\n function func(x)\n use nrtype\n real(dp), intent(in) :: x ! Variables\n real(dp) :: func ! Function\n end function func\n end interface functn\n\n cdo1 = 0._dp\n ! Size of the coefficient array.\n n = size(coef1)-1\n ! Check if N is Even.\n cne: if (mod(n,2) == 0) then\n cde: do i = 0, n\n cdo1 = cdo1 + coef1(n-i+1) * func( x + (n/2-i)*h )\n end do cde\n else cne\n cdo: do i = 0, n\n cdo1 = cdo1 + coef1(n-i+1) * ( func( x - h/2._dp + (n/2._dp-i)*h ) + func( x + h/2._dp + (n/2._dp-i)*h ) )/2_dp\n end do cdo\n end if cne\n cdo1 = cdo1/h**n\n end function cdo1\n\nend module num_diff\n", "meta": {"hexsha": "76e23ad467207773877e809b1bc1324ad35fbf1b", "size": 7240, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "numerical_differentiation/num_diff.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": "numerical_differentiation/num_diff.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": "numerical_differentiation/num_diff.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.5485232068, "max_line_length": 146, "alphanum_fraction": 0.5459944751, "num_tokens": 2442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620550745211, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8250726513132075}} {"text": "PROGRAM MAIN\n\n IMPLICIT NONE\n\n INTEGER :: i, sgn\n INTEGER, PARAMETER :: max_iter = 100\n REAL :: term, sin_approx, x, last_approx\n REAL :: threshold\n\n x = 3.14159/ 3.0 ! Pi/3\n\n threshold = 0.1/100.0 !0.1%\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\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 term = sgn * term * x**2 / REAL(i)/ REAL(i-1)\n\n sin_approx = sin_approx + term\n\n ! Check fractional change and terminate if below threshold\n IF(ABS((sin_approx-last_approx)/sin_approx) < threshold) THEN\n EXIT\n END IF\n\n last_approx = sin_approx\n sgn = -1 * sgn\n\n END DO\n\n PRINT*, \"An approximation to sin(x) for x=\", x, \" is: \", sin_approx\n\n ! The value of 'i' after the loop is well defined and is the last iteration we ran\n PRINT*, \"Convergence took \", i, \" iterations\"\n\nEND PROGRAM\n", "meta": {"hexsha": "f5e2e3353d52cf3827210670a4e2beff5565849a", "size": 1143, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Sin_threshold.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_threshold.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_threshold.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": 24.3191489362, "max_line_length": 84, "alphanum_fraction": 0.6640419948, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.8250672576714363}} {"text": "program test_quadratic_equation\n implicit none\n real(16) :: a ,b ,c, x_int_1, x_int_2\n a = 1\n b = 3\n c = -18\n call quad_eq(a ,b, c, x_int_1, x_int_2)\n print *, x_int_1, x_int_2\n \nend program test_quadratic_equation\n\n\nsubroutine quad_eq(a, b, c, result1, result2) \n !-b(+-)sqrt(b^2-4ac)\n !------------------\n ! 2a\n implicit none\n real(16), intent(in) :: a, b, c\n real(16), intent(out) :: result1, result2\n real(16) :: inside_sqrt\n \n if ((b**2 - (4 * a * c)) < 0) then\n print *, \"the result will be imaginary\"\n return\n end if\n \n inside_sqrt = b**2 - 4 * a * c\n \n result1 = (-b + sqrt(inside_sqrt))/2 * a\n result2 = (-b - sqrt(inside_sqrt))/2 * a\n \nend subroutine quad_eq\n\n\n\n", "meta": {"hexsha": "d509237f4cb7e0a0b2d335ecbbdf7ee9fe75ef08", "size": 763, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "quadratic_equation.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": "quadratic_equation.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": "quadratic_equation.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": 21.1944444444, "max_line_length": 47, "alphanum_fraction": 0.5386631717, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.824787341814952}} {"text": "!=======================================================================\n! Created by\n! Keurfon Luu \n! MINES ParisTech - Centre de Géosciences\n! PSL - Research University\n!=======================================================================\n\nprogram example_rand\n\n use forlab, only: IPRE, RPRE, randi, randu, randn, randperm, rng, &\n disp, num2str, mean, std, skewness, kurtosis, k2test, &\n kde, chol, repmat, linspace, prctile, horzcat, vertcat, &\n chi2rand, chi2inv, zeros, var, savebin\n\n implicit none\n\n integer(kind = IPRE) :: i, m, n, n1, n2, df\n integer(kind = IPRE), dimension(:), allocatable :: idx, idx2\n real(kind = RPRE) :: sig\n real(kind = RPRE), dimension(:), allocatable :: x, y, mu, f1, xi, yi\n real(kind = RPRE), dimension(:,:), allocatable :: A, B, Sigma, L, R, f2, gam\n character(len = :), allocatable :: outdir\n\n ! Output directory\n outdir = \"examples/rand/\"\n call system(\"rm -rf \" // outdir)\n call system(\"mkdir -p \" // outdir)\n\n ! Initialize random number generation\n call rng() ! The seed is set according to the current time\n\n ! Create random vector of integers (not unique/unique)\n print *, \"Random integers (not unique/unique):\"\n\n idx = randi([ 1, 10 ], 9) ! Random integers between in [ 1, 15 ]\n idx2 = randperm(10, 9) ! Random unique integers between in [ 1, 10 ]\n\n call disp(horzcat(idx, idx2))\n\n ! Create uniform 1D data\n print *; print *, \"Uniform 1D data (Y being permutation of X):\"\n\n n = 10\n x = randu(n) * 10. - 5. ! Uniformly distributed in [ -5, 5 ]\n idx = randperm(n) ! Random permutation\n y = x(idx) ! Shuffle vector x\n\n print *, \" X Y\"\n call disp(horzcat(x, y))\n\n ! Create normal 1D data\n print *; print *, \"Statistics for 100000 normally distributed samples:\"\n\n n = 100000\n x = randn(n) ! Normally distributed with mu = 0 and std = 1\n\n print *, \"Mean: \" // num2str(mean(x))\n print *, \"Standard deviation: \" // num2str(std(x))\n print *, \"Skewness: \" // num2str(skewness(x))\n print *, \"Kurtosis: \" // num2str(kurtosis(x))\n print *, \"P-value: \" // num2str(k2test(x))\n print *, \"5th percentile: \" // num2str(prctile(x, 5))\n print *, \"95th percentile: \" // num2str(prctile(x, 95))\n print *, \"Percentage of absolute deviations lower than 1:\"\n print *, num2str(count(abs(x) .le. 1.)/real(n, RPRE)*100., \"(F6.2)\") // \"%\"\n print *, \"Percentage of absolute deviations lower than 2:\"\n print *, num2str(count(abs(x) .le. 2.)/real(n, RPRE)*100., \"(F6.2)\") // \"%\"\n\n ! Create chi-square 1D data\n print *; print *, \"Statistics for 100000 chi-square distributed samples \" &\n // \"with 10 degrees of freedom:\"\n\n n = 100000\n df = 10\n x = chi2rand(df, n) ! Chi-square distributed with df = 10\n\n print *, \"Mean: \" // num2str(mean(x)) &\n // \" (\" // num2str(real(df, RPRE)) // \" expected)\"\n print *, \"Variance: \" // num2str(var(x)) &\n // \" (\" // num2str(2.*df) // \" expected)\"\n print *, \"Skewness: \" // num2str(skewness(x)) &\n // \" (\" // num2str(sqrt(8./df)) // \" expected)\"\n print *, \"Kurtosis: \" // num2str(kurtosis(x)) &\n // \" (\" // num2str(12./df + 3.) // \" expected)\"\n print *, \"5th percentile: \" // num2str(prctile(x, 5)) &\n // \" (\" // num2str(chi2inv(real(0.05, RPRE), df)) // \" expected)\"\n print *, \"95th percentile: \" // num2str(prctile(x, 95)) &\n // \" (\" // num2str(chi2inv(real(0.95, RPRE), df)) // \" expected)\"\n\n ! Create uniform 2D data\n print *; print *, \"Uniform 2D data:\"\n\n n = 5\n A = randu(n, n) * 10. - 5. ! Uniformly distributed in [ -5, 5 ]\n\n call disp(A)\n\n ! The same can be done for 3D data with randu(n, n, n)\n\n ! Create normal 2D data\n print *; print *, \"Normal 2D data:\"\n\n A = randn(n, n) ! Normally distributed with mu = 0 and std = 1\n\n call disp(A)\n\n ! The same can be done for 3D data with randn(n, n, n)\n\n ! 1D Kernel Density Estimation\n print *; print *, \"1D Kernel Density Estimation:\"\n\n ! Bell 1\n n1 = 500\n x = 2. + 1.5 * randn(n1)\n\n ! Bell 2\n n2 = 1000\n x = [ x, 7. + 1. * randn(n2) ]\n\n xi = linspace(-5, 15, 200)\n call kde(x, f1, xi)\n\n call savebin(outdir // \"data1d.bin\", x)\n call savebin(outdir // \"data1d_kde.bin\", f1)\n call savebin(outdir // \"data1d_kde_xaxis.bin\", xi)\n\n print *, \"Results saved in \" // outdir\n deallocate(xi)\n\n ! 2D Kernel Density Estimation\n print *; print *, \"2D Kernel Density Estimation:\"\n\n ! Bell 1\n n1 = 250\n Sigma = reshape( [ 3., 0., 0., 0.5 ], [ 2, 2 ] )\n L = chol(Sigma)\n R = randn(2, n1)\n mu = [ 3., 3. ]\n B = transpose( matmul(L, R) + repmat(mu, size(R, 2)))\n A = B\n\n ! Bell 2\n n2 = 500\n Sigma = reshape( [ 2., 0.5, 0.5, 1. ], [ 2, 2 ])\n L = chol(Sigma)\n R = randn(2, n2)\n mu = [ 6., -3. ]\n B = transpose( matmul(L, R) + repmat(mu, size(R, 2)))\n A = vertcat(A, B)\n\n xi = linspace(-5, 15, 200)\n yi = linspace(-10, 10, 200)\n call kde(A, f2, xi, yi)\n\n call savebin(outdir // \"data2d.bin\", A)\n call savebin(outdir // \"data2d_kde.bin\", f2)\n call savebin(outdir // \"data2d_kde_xaxis.bin\", xi)\n call savebin(outdir // \"data2d_kde_yaxis.bin\", yi)\n\n print *, \"Results saved in \" // outdir\n\n print *; print *, \"Run script /utils/view_kde.py to check results.\"\n\n ! Checking the property: if X ~ N(mu, sigma²), then (n-1)S²/sigma²\n ! follows a chi-square distribution with (n-1) degrees of freedom\n print *; print *, \"Checking the property:\"\n print *, \"If X ~ N(mu, sigma²), then (n-1)S²/sigma² follows \" &\n // \"a chi-square distribution with (n-1) degrees of freedom\"\n\n n = 10000\n sig = 2.\n df = 10\n x = zeros(n)\n do i = 1, n\n x(i) = (df+1.) * var(randn(df+1) * sig) / sig**2\n end do\n y = chi2rand(df, n)\n\n call savebin(outdir // \"randn_to_chi2.bin\", x)\n call savebin(outdir // \"randchi2.bin\", y)\n\n print *, \"Number of degrees of freedom: \" // num2str(df)\n print *, \"Results saved in \" // outdir\n\n print *; print *, \"Run script /utils/view_chi2.py to check results.\"\n\n print *\n\nend program example_rand\n", "meta": {"hexsha": "43f2c8e5fab04a5c4fc68bf6e9c4b3726451f031", "size": 6042, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/example_rand.f90", "max_stars_repo_name": "Kefeng91/Forlab", "max_stars_repo_head_hexsha": "62b80c031fe5f283e6696be0353c13f4ba5886de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-10-25T13:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-17T18:40:12.000Z", "max_issues_repo_path": "src/tests/example_rand.f90", "max_issues_repo_name": "Kefeng91/Forlab", "max_issues_repo_head_hexsha": "62b80c031fe5f283e6696be0353c13f4ba5886de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-24T16:19:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-24T16:19:09.000Z", "max_forks_repo_path": "src/tests/example_rand.f90", "max_forks_repo_name": "Kefeng91/Forlab", "max_forks_repo_head_hexsha": "62b80c031fe5f283e6696be0353c13f4ba5886de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-04-15T22:34:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-08T05:26:56.000Z", "avg_line_length": 31.8, "max_line_length": 78, "alphanum_fraction": 0.5716650116, "num_tokens": 2075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.8247521556935361}} {"text": "subroutine trapezoidal (b, trap_sum)\n ! Author : Anantha Rao (Reg no : 20181044)\n ! Program to compute the value of erf(x=b)\n ! Erf(x) = 2/sqrt(pi)*Int_0^x e^{-x^2}\n implicit none\n integer :: i,n\n ! n : number of bins\n ! i : counter\n\n REAL*8:: a,b,h, fa, fb, trap_sum, func\n ! a : Lower limit of Error function\n ! b : Upper limit of Error function\n ! fa : erf(x=a)\n ! fb : erf(x=b)\n ! trap_sum : value of the integral\n ! func : external function\n\n real*8, parameter :: pi = 2.0d0*asin(1.0d0)\n n = 10000 \n a = 0.0d0\n h = (b-a)/real(n)\n fa = func(a)/2.0d0\n fb = func(b)/2.0d0\n trap_sum = 0.0d0\n\n do i=1, n-1\n trap_sum=trap_sum+func(a+h*i)\n end do\n trap_sum=(trap_sum+fa+fb)*h\nend subroutine\n\nreal*8 function func(x)\n ! Evaluates exp(-x^2)\n implicit none\n real*8::x\n real*8, parameter :: pi = 2.0d0*asin(1.0d0) \n func=exp(-(x*x))\nend function\n\nprogram main\n implicit none\n real*8 :: b, result\n ! b : upper limit of the integral\n real*8, parameter :: pi = 2.0d0*asin(1.0d0) \n print*,\"Computing Error function values...\"\n b=-3.0d0\n 5 b=b + 0.005d0\n print*, \"Computing Erf(x) for x=\",b\n call trapezoidal(b, result)\n open(1,file = '20181044_D_erfvalues.dat')\n write(1,*) b, 2.0d0*result/(sqrt(pi))\n if (b .lt. 3.0d0) goto 5\n print*,\"Output written to D_erfvalues.dat\"\nend program main\n\n", "meta": {"hexsha": "589fd59df2e745f3f03aad3d1437cd9cdf6978b5", "size": 1421, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn01_solns/Assgn01_D_sourcecode.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/assgn01_solns/Assgn01_D_sourcecode.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/assgn01_solns/Assgn01_D_sourcecode.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": 25.375, "max_line_length": 51, "alphanum_fraction": 0.584799437, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.8246770910547049}} {"text": "************************************************************************\n* This file contains routines for the transformation and\n* back-transformation of points between a reference quadrilateral\n* and the \"real\" element.\n************************************************************************\n\nC **********************************************************************\nC Explaination of the transformation:\nC\nC We want to perform a transformation from the reference quadrilateral\nC [-1,1]x[-1,1] onto a \"real\" quadrilaterl:\nC\nC (-1,1) ___ (1,1) (x4,y4) ___ (x3,y3)\nC | | / \\\nC |__| => /____\\\nC (-1,-1) (1,-1) (x1,y1) (x2,y2) \nC\nC By theory this can by done with a bilinear mapping, i.e. a mapping\nC Psi:R^2->R^2 of the form:\nC\nC Psi (xi1) = ( a1 + a2*xi1 + a3*xi2 + a4*xi1*xi2 )\nC (xi2) ( b1 + b2*xi1 + b3*xi2 + b4*xi1*xi2 )\nC\nC Our special transformation has to map:\nC\nC Psi(-1,-1) = (x1,y1)\nC Psi( 1,-1) = (x2,y2)\nC Psi( 1, 1) = (x3,y3)\nC Psi(-1, 1) = (x4,y4)\nC\nC This gives the linear system:\nC\nC a1 - a2 - a3 - a4 = x1 b1 - b2 - b3 - b4 = y1\nC a1 + a2 - a3 - a4 = x2 b1 + b2 - b3 - b4 = y2\nC a1 + a2 + a3 + a4 = x3 b1 + b2 + b3 + b4 = y3\nC a1 - a2 + a3 - a4 = x4 b1 - b2 + b3 - b4 = y4\nC\nC Reorder this to calculate the ai:\nC\nC a1 = 1/4 * ( x1 + x2 + x3 + x4) b1 = 1/4 * ( y1 + y2 + y3 + y4)\nC a2 = 1/4 * (-x1 + x2 + x3 - x4) b2 = 1/4 * (-y1 + y2 + y3 - y4)\nC a3 = 1/4 * (-x1 - x2 + x3 + x4) b3 = 1/4 * (-y1 - y2 + y3 + y4)\nC a4 = 1/4 * ( x1 - x2 + x3 - x4) b4 = 1/4 * ( y1 - y2 + y3 - y4)\nC\nC The factors in the brackets in these equations are only dependent on \nC the corners of the quadrilateral, not of the current point. So they\nC are constant for all points we want to map from the reference\nC element to the real one. We call them here \"auxiliary Jacobian factors\".\nC They can be calculated with QINIJF in advance for all points that\nC have to be mapped. To be more exact, QINIJF calculates:\nC\nC J1 = 1/2 * (-x1 - x2 + x3 - x4)\nC J2 = 1/2 * ( x1 - x2 + x3 - x4)\nC\nC J3 = 1/2 * (-y1 + y2 - y3 + y4)\nC J4 = 1/2 * (-y1 + y2 + y3 - y4)\nC\nC Using these factors, one can write:\nC\nC a1 = 1/4 * ( x1 + x2 + x3 + x4) = 1/2 * (x1 + x2 + J1)\nC a2 = 1/4 * (-x1 + x2 + x3 - x4) = 1/2 * (x2 - x1 + J2)\nC a3 = 1/4 * (-x1 - x2 + x3 + x4) = 1/2 * J1 \nC a4 = 1/4 * ( x1 - x2 + x3 - x4) = 1/2 * J2\nC\nC b1 = 1/4 * ( y1 + y2 + y3 + y4) = 1/2 * (y1 + y3 + J3)\nC b2 = 1/4 * (-y1 + y2 + y3 - y4) = 1/2 * J4\nC b3 = 1/4 * (-y1 - y2 + y3 + y4) = 1/2 * (y3 - y1 - J4)\nC b4 = 1/4 * ( y1 - y2 + y3 - y4) = 1/2 * J3\nC\nC The Jacobian matrix of the bilinear transformation is now \nC calculated as usual by partial differentiation. Thing above \nC coefficients ai and bi one can write:\nC\nC DPhi ( xi1 ) = ( a2 + a4*xi2 a3 + a4*xi1 )\nC ( xi2 ) ( b2 + b4*xi2 b3 + b4*xi1 )\nC\nC = ( 1/2*(x2-x1+J2) + 1/2*J2*xi2 1/2*J1 + 1/2*J2*xi1 )\nC ( 1/2*J4 + 1/2*J3*xi2 1/2*(y3-y1-J4) + 1/2*J3*xi1 )\nC\nC which gives the Jacobian determinant of the 2x2-matrix:\nC\nC det DPhi (xi1,xi2) = (DPhi[1,1]*DPhi[2,2] - DPhi[1,2]*DPhi[2,1]) (xi1,xi2)\nC\nC Using these information makes it possible to map a point (XI1,XI2)\nC on the reference element to coordinates (XX,YY) on the real element by:\nC\nC (XX,YY) := Psi(XI1,XI2) \nC **********************************************************************\n\n************************************************************************\n* Calculate auxiliary Jacobian factors\n*\n* This routine builds up constant factors that are later used during\n* the transformation from the reference element to the real element.\n* This is used for saving some computational time...\n*\n* In:\n* DCOORD - array [1..2,1..4] of double\n* Coordinates of the four corners of the real quadrilateral.\n* DCOORD(1,.) saves the X-, DCOORD(2,.) the Y-coordinates.\n* \n* Out:\n* DJF - array [1..2,1..2] of double\n* Auxiliary constant factors for calculation of\n* Jacobian matrix\n************************************************************************\n\n SUBROUTINE QINIJF (DCOORD,DJF)\n \n IMPLICIT NONE\n\nC parameters\n \n DOUBLE PRECISION DCOORD (2,4),DJF(2,2)\n \n DJF(1,1)=0.5D0*(-DCOORD(1,1)-DCOORD(1,2)+DCOORD(1,3)+DCOORD(1,4))\n DJF(1,2)=0.5D0*( DCOORD(1,1)-DCOORD(1,2)+DCOORD(1,3)-DCOORD(1,4))\n DJF(2,1)=0.5D0*(-DCOORD(2,1)+DCOORD(2,2)-DCOORD(2,3)+DCOORD(2,4))\n DJF(2,2)=0.5D0*(-DCOORD(2,1)+DCOORD(2,2)+DCOORD(2,3)-DCOORD(2,4))\n \n END\n\n************************************************************************\n* Quadrilateral transformation of a point from the reference element\n* onto the real element\n*\n* This subroutine performs two tasks:\n* -Initialisation of a a given 2x2 matrix with the\n* mapping information from the reference element to the \"real\"\n* quadrilateral. Calculation of the Jacobian determinant\n* -Transformation of a given point on the reference element onto\n* the \"real\" element\n* Both things are performed simultaneously because the jacobian\n* determinant is dependent of the point.\n*\n* Before this routine can be called, the auxiliary factors DJF\n* have to be calculated with QINIJF for the considered element.\n*\n* In:\n* DCOORD - array [1..2,1..4] of double\n* Coordinates of the four corners of the real quadrilateral.\n* DCOORD(1,.) saves the X-, DCOORD(2,.) the Y-coordinates.\n* DJF - array [1..2,1..2] of double\n* Auxiliary constants for the considered element with\n* coordinates in DCOORD; have to be computed previously\n* by QINIJF.\n* (DXPAR,DYPAR) - Coordinates of a point on the reference element\n* \n* Out:\n* DJAC - array [1..2,1..2] of double\n* 2x2-system that receives the Jacobian matrix of the\n* mapping. When calling this routine this variable should\n* point to the DJAC variable in the COMMON block for\n* later calculations.\n* DETJ - Determinant of the jacobian matrix\n* (DXREAL,DYREAL) - Coordinates of the point on the real element\n************************************************************************\n\n SUBROUTINE QTRAF (DCOORD,DJF,DJAC,DETJ,DPARX,DPARY,DXREAL,DYREAL)\n \n IMPLICIT NONE\n\nC parameters\n \n DOUBLE PRECISION DCOORD (2,4),DJF(2,2),DJAC(2,2),DETJ\n DOUBLE PRECISION DPARX,DPARY,DXREAL,DYREAL\n \nC Jacobian matrix\n \n DJAC(1,1)=0.5D0 * (DCOORD(1,2)-DCOORD(1,1)+DJF(1,2)) +\n * 0.5D0 * DJF(1,2)*DPARY\n DJAC(1,2)=0.5D0 * DJF(1,1) + \n * 0.5D0 * DJF(1,2)*DPARX\n DJAC(2,1)=0.5D0 * DJF(2,2) - \n * 0.5D0 * DJF(2,1)*DPARY\n DJAC(2,2)=0.5D0 * (DCOORD(2,3)-DCOORD(2,1)-DJF(2,2)) - \n * 0.5D0 * DJF(2,1)*DPARX\n\nC Determinant of the mapping\n\n DETJ = DJAC(1,1)*DJAC(2,2) - DJAC(1,2)*DJAC(2,1)\n \nC Map the point to the real element\n\n DXREAL = 0.5D0*(DCOORD(1,1)+DCOORD(1,2)+DJF(1,1)) +\n * 0.5D0*(DCOORD(1,2)-DCOORD(1,1)+DJF(1,2))*DPARX +\n * 0.5D0*DJF(1,1)*DPARY +\n * 0.5D0*DJF(1,2)*DPARX*DPARY\n DYREAL = 0.5D0*(DCOORD(2,1)+DCOORD(2,3)+DJF(2,1)) +\n * 0.5D0*DJF(2,2)*DPARX +\n * 0.5D0*(DCOORD(2,3)-DCOORD(2,1)-DJF(2,2))*DPARY -\n * 0.5D0*DJF(2,1)*DPARX*DPARY\n\n END\n\n************************************************************************\n* Calculate Jacobian determinant of mapping from reference- to\n* real element.\n*\n* This routine only calculates the Jacobian determinant. of the\n* mapping. this is on contrast to QTRAF, which not only calculates\n* this determinant but also maps the point. So this routine\n* can be used to speed up the code if the coordinates of the\n* mapped point already exist.\n*\n* Before this routine can be called, the auxiliary factors DJF\n* have to be calculated with QINIJF for the considered element.\n*\n* In:\n* DCOORD - array [1..2,1..4] of double\n* Coordinates of the four corners of the real quadrilateral.\n* DCOORD(1,.) saves the X-, DCOORD(2,.) the Y-coordinates.\n* DJF - array [1..2,1..2] of double\n* Auxiliary constants for the considered element with\n* coordinates in DCOORD; have to be computed previously\n* by QINIJF.\n* \n* Out:\n* DJAC - array [1..2,1..2] of double\n* 2x2-system that receives the Jacobian matrix of the\n* mapping. When calling this routine this variable should\n* point to the DJAC variable in the COMMON block for\n* later calculations.\n* DETJ - Determinant of the jacobian matrix\n************************************************************************\n\n SUBROUTINE QTRDET (DCOORD,DJF,DJAC,DETJ,DPARX,DPARY)\n \n IMPLICIT NONE\n\nC parameters\n \n DOUBLE PRECISION DCOORD (2,4),DJF(2,2),DJAC(2,2),DETJ\n DOUBLE PRECISION DPARX,DPARY\n \nC Jacobian matrix\n \n DJAC(1,1)=0.5D0 * (DCOORD(1,2)-DCOORD(1,1)+DJF(1,2)) +\n * 0.5D0 * DJF(1,2)*DPARY\n DJAC(1,2)=0.5D0 * DJF(1,1) + \n * 0.5D0 * DJF(1,2)*DPARX\n DJAC(2,1)=0.5D0 * DJF(2,2) - \n * 0.5D0 * DJF(2,1)*DPARY\n DJAC(2,2)=0.5D0 * (DCOORD(2,3)-DCOORD(2,1)-DJF(2,2)) - \n * 0.5D0 * DJF(2,1)*DPARX\n\nC Determinant of the mapping\n\n DETJ = DJAC(1,1)*DJAC(2,2) - DJAC(1,2)*DJAC(2,1)\n \n END\n\n************************************************************************\n* Quadrilateral back-transformation\n*\n* This subroutine is to find the parameter values for a given point\n* (x,y) in real coordinates.\n* \n* Remark: This is a difficult task, as usually in FEM codes the\n* parameter values are known and one wants to obtain the real\n* coordinates.\n* \n* inverting the bilinear trafo in a straightforward manner by using \n* pq-formula does not work very well, as it is numerically unstable. \n* For parallelogram-shaped elements, one would have to introduce a\n* special treatment. For nearly parallelogram-shaped elements, this \n* can cause a crash as the argument of the square root can become \n* negative due to rounding errors. In the case of points near\n* the element borders, we divide nearly 0/0.\n* \n* Therefore, we have implemented the algorithm described in\n* \n* Introduction to Finite Element Methods, Carlos Felippa,\n* Department of Aerospace Engineering Sciences and Center for \n* Aerospace Structures, http://titan.colorado.edu/courses.d/IFEM.d/ \n*\n* In:\n* DCOORD - array [1..2,1..4] of double\n* Coordinates of the four corners of the real quadrilateral.\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* (DXPAR,DYPAR) - Coordinates of the transformed point in the\n* reference element.\n************************************************************************\n\n SUBROUTINE QBTRAF (DCOORD, DXPAR, DYPAR, 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,4)\nC parameter values of (x,y)\n DOUBLE PRECISION DXPAR,DYPAR\n\nC local variables\n\n DOUBLE PRECISION X1,X2,X3,X4,Y1,Y2,Y3,Y4,XB,YB,XCX,YCX,XCE,YCE\n DOUBLE PRECISION A,J1,J2,X0,Y0,BXI,BETA,CXI,XP0,YP0,CETA\n DOUBLE PRECISION ROOT1,ROOT2,XIP1,XIP2,ETAP1,ETAP2,D1,D2\n\nC Get nodal x-coordinates\n X1 = DCOORD(1,1)\n X2 = DCOORD(1,2)\n X3 = DCOORD(1,3)\n X4 = DCOORD(1,4)\n\nC Get nodal y-coordinates\n Y1 = DCOORD(2,1)\n Y2 = DCOORD(2,2)\n Y3 = DCOORD(2,3)\n Y4 = DCOORD(2,4)\n\n XB = X1-X2+X3-X4\n YB = Y1-Y2+Y3-Y4\n\n XCX = X1+X2-X3-X4\n YCX = Y1+Y2-Y3-Y4\n\n XCE = X1-X2-X3+X4\n YCE = Y1-Y2-Y3+Y4\n\n A = 0.5*((X3-X1)*(Y4-Y2)-(X4-X2)*(Y3-Y1))\n\n J1 = (X3-X4)*(Y1-Y2)-(X1-X2)*(Y3-Y4)\n J2 = (X2-X3)*(Y1-Y4)-(X1-X4)*(Y2-Y3)\n\n X0 = 0.25*(X1+X2+X3+X4)\n Y0 = 0.25*(Y1+Y2+Y3+Y4)\n\n XP0 = DXREAL-X0\n YP0 = DYREAL-Y0\n\n BXI = A-XP0*YB+YP0*XB\n BETA = -A-XP0*YB+YP0*XB\n\n CXI = XP0*YCX-YP0*XCX\n CETA = XP0*YCE-YP0*XCE\n\n ROOT1 = -DSQRT(BXI**2-2.0*J1*CXI)-BXI\n ROOT2 = DSQRT(BXI**2-2.0*J1*CXI)-BXI\n IF (ROOT1.NE.0D0) THEN\n XIP1 = 2.0*CXI/ROOT1\n ELSE\n XIP1 = 1E15\n END IF\n IF (ROOT2.NE.0D0) THEN\n XIP2 = 2D0*CXI/ROOT2\n ELSE\n XIP2 = 1E15\n END IF\n\n ROOT1 = DSQRT(BETA**2+2D0*J2*CETA)-BETA\n ROOT2 = -DSQRT(BETA**2+2D0*J2*CETA)-BETA\n IF (ROOT1.NE.0D0) THEN\n ETAP1 = 2D0*CETA/ROOT1\n ELSE\n ETAP1 = 1D15\n END IF\n IF (ROOT2.NE.0D0) THEN\n ETAP2 = 2D0*CETA/ROOT2\n ELSE\n ETAP2 = 1D15\n END IF\n\n D1 = DSQRT(XIP1**2+ETAP1**2)\n D2 = DSQRT(XIP2**2+ETAP2**2)\n\n IF (D1.LT.D2) THEN\n DXPAR = XIP1\n DYPAR = ETAP1\n ELSE\n DXPAR = XIP2\n DYPAR = ETAP2\n END IF\n\n END", "meta": {"hexsha": "f4f8b96ee9ce2e243cf1feebec5b553040a27f23", "size": 13101, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/geometry/qtrafo.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/qtrafo.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/qtrafo.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": 34.2062663185, "max_line_length": 83, "alphanum_fraction": 0.5536218609, "num_tokens": 4785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422213778251, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.824674321860137}} {"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 real(dp) :: x_bar = 1.d0, sigma_square = 1.d0\n\n interface\n function Gaussian_Box_Muller_method(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_method\n end function Gaussian_Box_Muller_method\n end interface\n\n call random_seed(size=n)\n allocate(seed(n))\n seed = 1\n call random_seed(put=seed)\n open(unit=11, file='1.2.2.2-Gaussian-Random-Variable.txt', status='replace')\n do i = 1,10000\n write(11, '(f16.8)') Gaussian_Box_Muller_method(x_bar, sigma_square)\n end do\n close(11)\nend program main\n\nfunction Gaussian_Box_Muller_method(x_bar_, sigma_square_)\n ! Box-Muller 法产生服从正态分布随机数\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 :: x_bar_, sigma_square_ ! 均值和方差\n real(dp) :: Gaussian_Box_Muller_method\n\n real(dp) :: x_bar, sigma_square\n real(dp) :: u, v\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 call random_number(u)\n call random_number(v)\n Gaussian_Box_Muller_method = sqrt(-2.d0 * log(u)) * cos(2.d0 * pi * v)\n ! Gaussian_Box_Muller_method = sqrt(-2.d0 * log(u)) * sin(2.d0 * pi * v)\n Gaussian_Box_Muller_method = Gaussian_Box_Muller_method * sqrt(sigma_square) + x_bar\nend function Gaussian_Box_Muller_method", "meta": {"hexsha": "54a2b28c6a61778f52c87e56ea3e8842fa33b794", "size": 1846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.2.2.2-Box-Muller-Method.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.2-Box-Muller-Method.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.2-Box-Muller-Method.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.7666666667, "max_line_length": 88, "alphanum_fraction": 0.6538461538, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.8245363162027138}} {"text": "program chicharronera2\n! ------------------------------------------------------------------\n! en este programa se calculan las raíces de la ecuación cuadrática ax**2+bx+c=0\n! ------------------------------------------------------------------\n! Declaración de los tipos tipos\n! ------------------------------------------------------------------\nimplicit none\nreal :: a,b,c\n! coeficientes de la ecuación\nreal :: discr\n! discriminante de la ecuación\nreal :: x1,x2\n! variables para las posibles soluciones soluciones\nreal :: term, den\n\n\n! Entrada de datos\n\nwrite (*,*)\"Ingrese coeficientes a,b,c de una ecuacion cuadratica de la forma ax²+bx+c=0 con una coma entre ellos ejemplo: 4,9,6\"\nread(*,*) 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\ndiscr = b**2 - 4.0*a*c\nden = 2.0*a\nterm = SQRT(ABS(discr))\nif (discr >= 0 ) then\n x1 = (-b+term)/den\n x2 = (-b-term)/den\n\n print*, \"a continuación se muestran las raices de la ecuación\"\n write(*,*) \"x1 = \", x1\n write(*,*) \"x2 = \", x2\nelse\n x1 = -b/den\n x2 = term/den\nprint*, \"a continuación se muestran las raices con su parte real e imaginaria\"\n write(*,*) \"x1 = (\", x1, \" ,\", x2, \")\"\n write(*,*) \"x1 = (\", x1, \" ,\", -x2, \")\"\nendif\nstop\n\nend program chicharronera2\n", "meta": {"hexsha": "f345540b30ab2784c671ecdf62f7822c30d4be16", "size": 1323, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chicharronera2.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": "chicharronera2.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": "chicharronera2.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": 27.5625, "max_line_length": 129, "alphanum_fraction": 0.5427059713, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305349799242, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.8243819528441738}} {"text": "program main\n implicit none\n\n integer :: i\n interface\n function Tausworthe_shift_counter_R250(seed_)\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, intent(in), optional :: seed_\n real(dp) :: Tausworthe_shift_counter_R250\n end function Tausworthe_shift_counter_R250\n end interface\n\n do i = 1, 100\n write(*,*) Tausworthe_shift_counter_R250()\n end do\nend program main\n\nfunction Tausworthe_shift_counter_R250(seed_)\n ! Tausworthe 位移计数器法消除同余法产生的随机数的关联性\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n integer, intent(in), optional :: seed_\n real(dp) :: Tausworthe_shift_counter_R250\n\n integer :: i\n integer, save :: I_list(251) = [(-1, i = 1,251)]\n logical :: initialized = .false.\n integer, parameter :: m = 16807\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:250) = I_list(2:251)\n else\n I_list(2) = Congruential_16807(I_list(1))\n do i = 2,250\n I_list(i + 1) = Congruential_16807()\n end do\n initialized = .true.\n end if\n I_list(251) = ieor(I_list(1), I_list(148))\n Tausworthe_shift_counter_R250 = mod(I_list(251), m) / dble(m)\n\n contains\n function Congruential_16807(seed_)\n ! Schrage 方法产生 16807 产生器中的随机整数\n implicit none\n\n integer, 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 Tausworthe_shift_counter_R250", "meta": {"hexsha": "12a4d328797ecf41a68b989c3a6751c0a08489d2", "size": 2152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.5-Tausworthe-Shift-Counter.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.5-Tausworthe-Shift-Counter.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.5-Tausworthe-Shift-Counter.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.3157894737, "max_line_length": 65, "alphanum_fraction": 0.5664498141, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.8243253498728065}} {"text": "! To study the projectile motion and plot x,y at angle 45 degrees\r\n\r\nprogram Projectile\r\n implicit none\r\n\r\n real,parameter::g=9.81 ! acceleration due to gravity in m/s^2\r\n real,parameter::pi=3.1415926\r\n\r\n real::angle\r\n real::time\r\n real::theta\r\n real::U\r\n real::V\r\n real::Vx\r\n real::Vy\r\n real,dimension(100)::X_Array\r\n real,dimension(100)::Y_Array\r\n real::X\r\n real::Y\r\n real::total_time ! total time of flight\r\n real::max_height ! maximum height of projectile\r\n real::horizontal_range ! maximum range of projectile\r\n integer::t\r\n\r\n print*,\"Initial angle of launch (in degrees) - : \"\r\n read*,angle\r\n print*,\"Initial velocity of launch (in m/s) : \"\r\n read*,U\r\n print*,\"Time at which Position and Velocity needs to be calculated (in seconds) : \"\r\n read*,time\r\n\r\n angle=angle*pi/180 ! convert to radians\r\n X=U*cos(angle)*time\r\n Y=U*sin(angle)*time - g*time*time/2.0\r\n Vx=U*cos(angle)\r\n Vy=U*sin(angle)-g*time\r\n V=sqrt(Vx*Vx+Vy*Vy)\r\n theta=atan(Vy/Vx)*180/pi\r\n total_time=2*U*sin(angle)/g\r\n horizontal_range=U*U*sin(2*angle)/g\r\n max_height=U*U*sin(angle)*sin(angle)/2*g\r\n\r\n print*,\"Horizontal Displacement at given time = \",X\r\n print*,\"Vertical Displacement at given time = \",Y\r\n print*,\"Resultant Velocity at given time = \",V\r\n print*,\"Direction (in degree) at given time = \",theta\r\n print*,\"Total Time (in seconds) of flight = \",total_time\r\n print*,\"Horizontal Range of projectile = \",horizontal_range\r\n print*,\"Maximum Height of projectile = \",max_height\r\n\r\n do t=0,total_time\r\n X_Array(t)=U*cos(angle)*t\r\n Y_Array(t)=U*sin(angle)*t - g*t*t/2.0\n end do\r\n\r\n ! output data into a file\r\n open(1, file = 'Parabola_Motion.dat', status = 'new')\r\n do t=0,total_time\r\n write(1,*) X_Array(t), Y_Array(t)\r\n end do\r\n close(1)\r\n\nend program\r\n", "meta": {"hexsha": "5c66679fb80ff84411e265fd4daab1c40ad77ea4", "size": 1921, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "7_Projectile_Motion.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": "7_Projectile_Motion.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": "7_Projectile_Motion.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": 30.015625, "max_line_length": 88, "alphanum_fraction": 0.6220718376, "num_tokens": 570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9697854129326059, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.8242896494086788}} {"text": " PROGRAM Main\nC\nC *** Solution of Laplace's Equation.\nC ***\nC *** Uxx + Uyy = 0\nC *** 0 <= x <= pi, 0 <= y <= pi\nC *** U(x,pi) = sin(x), U(x,0) = U(0,y) = U(pi,y) = 0\nC ***\nC *** then U(x,y) = (sinh(y)*sin(x)) / sinh(pi)\nC ***\nC *** Should converge with\nC *** tol = 0.001 and M = 20 in 42 iterations.\nC *** and with tol = 0.001 and M = 100 in 198 iterations.\nC *** \nC\n INTEGER M\n PARAMETER (M = 100)\nC\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\nC\n PI = 4.0D0*DATAN(1.0D0)\nC\n h = PI/FLOAT(M+1)\nC\n DO i=0,M+1\n uold(i,M+1) = SIN(FLOAT(i)*h)\n END DO\nC\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\nC\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\nC\n omega = 2.0/(1.0+SIN(PI/FLOAT(M+1)))\n tol = 0.001\nC\n CALL SOR (unew, uold, solution, omega, tol, m, iters)\nC\n PRINT *, \" \"\n PRINT *, \" Omega = \", omega\n PRINT *, \" It took \", iters, \" iterations.\"\nC\n STOP\n END\nC\n\n REAL*8 FUNCTION ComputeError (solution, u, m, iters)\nC\n INTEGER m, iters\n REAL*8 u(0:m+1,0:m+1)\n REAL*8 solution(0:m+1,0:m+1)\nC\nC *** Local variables\nC\n REAL*8 error\n INTEGER i, j\n\n error = 0.0\nC\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\nC\n PRINT *, \"On iteration \", iters, \" error = \", error\nC\n ComputeError = error\nC\n RETURN\n END\nC\n SUBROUTINE SOR (unew, uold, solution, omega, tol, m, iters)\nC\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\nC\nC *** Local variables\nC\n REAL*8 error\n INTEGER i, j\nC\nC *** External function.\nC\n REAL*8 ComputeError\n EXTERNAL ComputeError\nC\nC *** Copy bonudary conditions.\nC\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\nC\nC *** Do SOR until 'tol' satisfied.\nC\n iters = 0\n error = ComputeError (solution, uold, m, iters)\nC\n DO WHILE (error .GE. tol)\nC\nC *** Do one iteration of SOR\nC\n DO j=1,m\n DO i=1,m\n unew(i,j) = uold(i,j) + 0.25*omega*\n 1 (unew(i-1,j) + unew(i,j-1) +\n 2 uold(i+1,j) + uold(i,j+1) -\n 3 4.0*uold(i,j))\n END DO\n END DO\nC\nC *** Copy new to old.\nC\n DO j=1,m\n DO i=1,m\n uold(i,j) = unew(i,j)\n END DO\n END DO\nC\nC *** Check error every 20 iterations.\nC\n iters = iters + 1\nC\n IF (MOD(iters,20) .EQ. 0) THEN\n error = ComputeError (solution, uold, m, iters)\n END IF\nC\n END DO\nC\n RETURN\n END\n", "meta": {"hexsha": "8c469066142d62a6b47371b4366c88d8a7fa6b8f", "size": 3113, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/labs-f77/lab6/sor.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/lab6/sor.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/lab6/sor.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.8926174497, "max_line_length": 69, "alphanum_fraction": 0.4696434308, "num_tokens": 1190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8887587817066392, "lm_q1q2_score": 0.8242022746226148}} {"text": "! VERSION 1.0 2/5/99\n!*********************************************************************\n\n! ASSOCIATED LEGENDRE FUNCTIONS\n! -----------------------------\n\n! This double precision function subroutine calculates the\n! value of the associated Legendre function via an upward\n! recurrence scheme taken from \"Numerical Recipes\", W. H. Press,\n! B. P. Flannery, S. A. Teulosky and W. T. Vetterling,1st ed.,\n! Cambridge Univ. Press, 1986.\n\n! written by DJS 10-SEP-87\n\n! Includes:\n\n! Uses:\n\n!*********************************************************************\n\n function plgndr(l,m,z)\n implicit none\n\n integer :: l,m\n double precision :: plgndr,z\n\n integer :: i\n double precision :: pmm,temp1,temp2,pmmp1,pmmp2\n\n intrinsic abs,sqrt\n\n!#####################################################################\n\n if ((m < 0) .OR. (m > l) .OR. (abs(z) > 1.0D0)) then\n go to 9999\n end if\n\n pmm=1.0D0\n\n!---------------------------------------------------------------------\n\n! calculate the starting point for the upward recurrence\n! on l using the formula :\n\n! m m 2 m/2\n! P (z)=(-1) (2m-1)!! (1-z )\n! m\n\n!---------------------------------------------------------------------\n\n if (m > 0) then\n temp1=sqrt((1.0D0-z)*(1.0D0+z))\n temp2=1.0D0\n do 10 i=1,m\n pmm=-pmm*temp1*temp2\n temp2=temp2+2.0D0\n 10 END DO\n end if\n\n!---------------------------------------------------------------------\n\n! do upward recursion on l using the formulae :\n\n! m m m\n! (l-m)P (z)= z(2l-1)P (z) - (l+m-1)P (z)\n! l l-1 l-2\n\n! or\n! m m\n! P (z) = z(2m+1) P (z) if l=m+1\n! m+1 m\n\n!---------------------------------------------------------------------\n\n if (l == m) then\n plgndr=pmm\n else\n pmmp1=z*(2*m+1)*pmm\n if (l == m+1) then\n plgndr=pmmp1\n else\n do 20 i=m+2,l\n pmmp2=(z*(2*i-1)*pmmp1-(i+m-1)*pmm)/(i-m)\n pmm=pmmp1\n pmmp1=pmmp2\n 20 END DO\n plgndr=pmmp2\n end if\n end if\n\n!---------------------------------------------------------------------\n! return to calling program\n!---------------------------------------------------------------------\n\n return\n\n!---------------------------------------------------------------------\n! exit from program if improper arguments detected\n!---------------------------------------------------------------------\n\n 9999 write (*,1000) l,m,z\n 1000 format('Improper arguments for PLGNDR: ', &\n i3,',',i3,',',g13.6)\n stop\n end function plgndr\n", "meta": {"hexsha": "cf23c68f0d66d90c4f2befef74bd0846e9463497", "size": 2948, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lsld2/minimalistic/plgndr.f90", "max_stars_repo_name": "Xiaoy01/lsld2", "max_stars_repo_head_hexsha": "b8079ad92cb186b899a83b5e00618b4d715592db", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lsld2/minimalistic/plgndr.f90", "max_issues_repo_name": "Xiaoy01/lsld2", "max_issues_repo_head_hexsha": "b8079ad92cb186b899a83b5e00618b4d715592db", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lsld2/minimalistic/plgndr.f90", "max_forks_repo_name": "Xiaoy01/lsld2", "max_forks_repo_head_hexsha": "b8079ad92cb186b899a83b5e00618b4d715592db", "max_forks_repo_licenses": ["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.8113207547, "max_line_length": 70, "alphanum_fraction": 0.328697422, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997378, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8241769123473133}} {"text": "PROGRAM c14_date\r\n!\r\n! Purpose:\r\n! To calculate the age of an organic sample from the percentage \r\n! of the original carbon 14 remaining in the sample.\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\nIMPLICIT NONE\r\n \r\n! Data dictionary: declare constants \r\nREAL,PARAMETER :: LAMDA = 0.00012097 ! The radioactive decay \r\n ! constant of carbon 14,\r\n ! in units of 1/years.\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nREAL :: age ! The age of the sample (years)\r\nREAL :: percent ! The percentage of carbon 14 remaining at the time\r\n ! of the measurement (%)\r\nREAL :: ratio ! The ratio of the carbon 14 remaining at the time\r\n ! of the measurement to the original amount of \r\n ! carbon 14 (no units)\r\n \r\n! Prompt the user for the percentage of C-14 remaining.\r\nWRITE (*,*) 'Enter the percentage of carbon 14 remaining:'\r\nREAD (*,*) percent\r\n \r\n! Echo the user's input value.\r\nWRITE (*,*) 'The remaining carbon 14 = ', percent, ' %.'\r\n\r\n! Perform calculations\r\nratio = percent / 100. ! Convert to fractional ratio\r\nage = (-1.0 / LAMDA) * log(ratio) ! Get age in years\r\n\r\n! Tell the user about the age of the sample.\r\nWRITE (*,*) 'The age of the sample is ', age, ' years.'\r\n \r\n! Finish up.\r\nEND PROGRAM c14_date\r\n\r\n", "meta": {"hexsha": "3a31fce474ba085e9e5cc7a8e6701ff61d91a9e2", "size": 1548, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap2/c14_date.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/c14_date.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/c14_date.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.1818181818, "max_line_length": 69, "alphanum_fraction": 0.5742894057, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9814534311480466, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.8241597897281336}} {"text": " MODULE random_poisson_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_poisson(lambda)\n!**********************************************************************\n! INTEGER FUNCTION IGNPOI( LAMBDA )\n! GENerate POIsson random deviate\n! Function\n! Generates a single random deviate from a Poisson\n! distribution with mean LAMBDA.\n! Arguments\n! LAMBDA --> The mean of the Poisson distribution from which\n! a random deviate is to be generated.\n! REAL LAMBDA\n! JJV (LAMBDA >= 0.0)\n! IGNPOI <-- The random deviate.\n! INTEGER IGNPOI (non-negative)\n! Method\n! Renames KPOIS 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! Computer Generation of Poisson Deviates\n! From Modified Normal Distributions.\n! ACM Trans. Math. Software, 8, 2\n! (June 1982),163-179\n!**********************************************************************\n!**********************************************************************C\n!**********************************************************************C\n! C\n! C\n! P O I S S O N 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 GENERATION OF POISSON DEVIATES C\n! FROM MODIFIED NORMAL DISTRIBUTIONS. C\n! ACM TRANS. MATH. SOFTWARE, 8,2 (JUNE 1982), 163 - 179. C\n! C\n! (SLIGHTLY MODIFIED VERSION OF THE PROGRAM IN THE ABOVE ARTICLE) C\n! C\n!**********************************************************************C\n! INTEGER FUNCTION IGNPOI(IR,LAMBDA)\n! INPUT: IR=CURRENT STATE OF BASIC RANDOM NUMBER GENERATOR\n! LAMBDA=MEAN LAMBDA OF THE POISSON DISTRIBUTION\n! OUTPUT: IGNPOI=SAMPLE FROM THE POISSON-(LAMBDA)-DISTRIBUTION\n! MUPREV=PREVIOUS LAMBDA, MUOLD=LAMBDA AT LAST EXECUTION OF STEP P OR CASE B\n! TABLES: COEFFICIENTS A0-A7 FOR STEP F. FACTORIALS FACT\n! COEFFICIENTS A(K) - FOR PX = FK*V*V*SUM(A(K)*V**K)-DEL\n! SEPARATION OF CASES A AND B\n! JJV I added a variable 'll' here - it is the 'l' for CASE A\n! JJV added this for case: lambda unchanged\n! JJV end addition - I am including vars in Data statements\n! JJV changed initial values of MUPREV and MUOLD to -1.0E37\n! JJV if no one calls IGNPOI with LAMBDA = -1.0E37 the first time,\n! JJV the code shouldn't break\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 INTEGER :: random_poisson\n! ..\n! .. Scalar Arguments ..\n REAL, INTENT (IN) :: lambda\n! ..\n! .. Local Scalars ..\n REAL, SAVE :: a0, a1, a2, a3, a4, a5, a6, a7, c, c0, c1, c2, c3, &\n d, muold, muprev, omega, p, p0, q, s\n REAL :: b1, b2, del, difmuk, e, fk, fx, fy, g, px, py, t, u, v, &\n x, xx\n INTEGER :: j, k, kflag\n INTEGER, SAVE :: l, ll, m\n! ..\n! .. Local Arrays ..\n REAL, SAVE :: fact(10)\n REAL :: pp(35)\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, ALOG, EXP, FLOAT, IFIX, MAX0, MIN0, SIGN, SQRT\n! ..\n! .. Data Statements ..\n DATA muprev, muold/ -1.0E37, -1.0E37/\n DATA a0, a1, a2, a3, a4, a5, a6, a7/ -.5, 0.3333333, -.2500068, &\n 0.2000118, -.1661269, 0.1421878, -.1384794, 0.1250060/\n DATA fact/1., 1., 2., 6., 24., 120., 720., 5040., 40320., &\n 362880./\n! ..\n! .. Executable Statements ..\n\n IF (lambda/=muprev) THEN\n IF (lambda<10.0) GO TO 50\n\n! C A S E A. (RECALCULATION OF S,D,LL IF LAMBDA HAS CHANGED)\n\n! JJV This is the case where I changed 'l' to 'll'\n! JJV Here 'll' is set once and used in a comparison once\n\n muprev = lambda\n s = SQRT(lambda)\n d = 6.0*lambda*lambda\n\n! THE POISSON PROBABILITIES PK EXCEED THE DISCRETE NORMAL\n! PROBABILITIES FK WHENEVER K >= M(LAMBDA). LL=IFIX(LAMBDA-1.1484)\n! IS AN UPPER BOUND TO M(LAMBDA) FOR ALL LAMBDA >= 10 .\n\n ll = IFIX(lambda-1.1484)\n END IF\n\n! STEP N. NORMAL SAMPLE - SNORM(IR) FOR STANDARD NORMAL DEVIATE\n\n g = lambda + s*random_standard_normal()\n IF (g>=0.0) THEN\n random_poisson = IFIX(g)\n\n! STEP I. IMMEDIATE ACCEPTANCE IF IGNPOI IS LARGE ENOUGH\n\n IF (random_poisson>=ll) RETURN\n\n! STEP S. SQUEEZE ACCEPTANCE - SUNIF(IR) FOR (0,1)-SAMPLE U\n\n fk = FLOAT(random_poisson)\n difmuk = lambda - fk\n u = random_standard_uniform()\n IF (d*u>=difmuk*difmuk*difmuk) RETURN\n END IF\n\n! STEP P. PREPARATIONS FOR STEPS Q AND H.\n! (RECALCULATIONS 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! APPROXIMATIONS TO THE DISCRETE NORMAL PROBABILITIES FK.\n! C=.1069/LAMBDA GUARANTEES MAJORIZATION BY THE 'HAT'-FUNCTION.\n\n IF (lambda/=muold) THEN\n muold = lambda\n omega = 0.3989423/s\n b1 = 0.4166667E-1/lambda\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/lambda\n END IF\n IF (g<0.0) GO TO 20\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=0 FOR CORRECT RETURN)\n\n kflag = 0\n GO TO 40\n\n! STEP Q. QUOTIENT ACCEPTANCE (RARE CASE)\n\n10 CONTINUE\n IF (fy-u*fy<=py*EXP(px-fx)) RETURN\n\n! STEP E. EXPONENTIAL SAMPLE - SEXPO(IR) FOR STANDARD EXPONENTIAL\n! DEVIATE E AND SAMPLE T FROM THE LAPLACE 'HAT'\n! (IF T <= -.6744 THEN PK < FK FOR ALL LAMBDA >= 10.)\n\n20 CONTINUE\n e = random_standard_exponential()\n u = random_standard_uniform()\n u = u + u - 1.0\n t = 1.8 + SIGN(e,u)\n DO WHILE (t<=(-.6744))\n e = random_standard_exponential()\n u = random_standard_uniform()\n u = u + u - 1.0\n t = 1.8 + SIGN(e,u)\n END DO\n random_poisson = IFIX(lambda+s*t)\n fk = FLOAT(random_poisson)\n difmuk = lambda - fk\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=1 FOR CORRECT RETURN)\n\n kflag = 1\n GO TO 40\n\n! STEP H. HAT ACCEPTANCE (E IS REPEATED ON REJECTION)\n\n30 CONTINUE\n IF (c*ABS(u)>py*EXP(px+e)-fy*EXP(fx+e)) GO TO 20\n RETURN\n\n! STEP F. 'SUBROUTINE' F. CALCULATION OF PX,PY,FX,FY.\n! CASE IGNPOI .LT. 10 USES FACTORIALS FROM TABLE FACT\n\n40 CONTINUE\n IF (random_poisson<10) THEN\n px = -lambda\n py = lambda**random_poisson/fact(random_poisson+1)\n ELSE\n\n! CASE IGNPOI .GE. 10 USES POLYNOMIAL APPROXIMATION\n! A0-A7 FOR ACCURACY WHEN ADVISABLE\n! .8333333E-1=1./12. .3989423=(2*PI)**(-.5)\n\n del = 0.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*ALOG(1.0+v) - difmuk - del\n ELSE\n\n px = fk*v*v*(((((((a7*v+a6)*v+a5)*v+a4)*v+a3)*v+ &\n a2)*v+a1)*v+a0) - del\n END IF\n py = 0.3989423/SQRT(fk)\n END IF\n 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) GO TO 30\n GO TO 10\n\n! C A S E B. (START NEW TABLE AND CALCULATE P0 IF NECESSARY)\n\n! JJV changed MUPREV assignment from 0.0 to initial value\n50 CONTINUE\n muprev = -1.0E37\n IF (lambda/=muold) THEN\n! JJV added argument checker here\n IF (lambda<0.0) THEN\n WRITE (*,*) 'LAMBDA < 0 in IGNPOI - ABORT'\n WRITE (*,*) 'Value of LAMBDA: ', lambda\n STOP 'LAMBDA < 0 in IGNPOI - ABORT'\n END IF\n! JJV added line label here\n muold = lambda\n m = MAX0(1,IFIX(lambda))\n l = 0\n p = EXP((-lambda))\n q = p\n p0 = p\n\n! STEP U. UNIFORM SAMPLE FOR INVERSION METHOD\n\n END IF\n60 CONTINUE\n u = random_standard_uniform()\n random_poisson = 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 LAMBDA=10)\n\n IF (l==0) GO TO 70\n j = 1\n IF (u>0.458) j = MIN0(l,m)\n DO k = j, l\n IF (u<=pp(k)) GO TO 90\n END DO\n IF (l==35) GO TO 60\n\n! STEP C. CREATION OF NEW POISSON PROBABILITIES P\n! AND THEIR CUMULATIVES Q=PP(K)\n\n70 CONTINUE\n l = l + 1\n DO k = l, 35\n p = p*lambda/FLOAT(k)\n q = q + p\n pp(k) = q\n IF (u<=q) GO TO 80\n END DO\n l = 35\n GO TO 60\n\n80 CONTINUE\n l = k\n90 CONTINUE\n random_poisson = k\n RETURN\n\n END FUNCTION random_poisson\n\n!*********************************************************************\n\n END MODULE random_poisson_mod\n", "meta": {"hexsha": "d1b5cccd4c19f6907dfe487906c518397f680765", "size": 10356, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_poisson_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_poisson_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_poisson_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.635451505, "max_line_length": 80, "alphanum_fraction": 0.4664928544, "num_tokens": 3004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.8237820537017662}} {"text": "program problem_39\n implicit none\n integer :: a, b, c, p, maximum, counter, chosen_p\n\n maximum = 0\n\n do p = 4, 1000\n counter = 0\n do a = 1, p - 2 \n do b = a + 1, p - 2\n c = p - a - b\n if (a*a + b*b == c*c) then\n counter = counter + 1\n endif\n enddo\n enddo\n if (counter > maximum) then\n maximum = counter\n chosen_p = p\n endif\n enddo\n\n print *, chosen_p\n \nend program problem_39", "meta": {"hexsha": "7174b433e5e9f5b9ca4d5f4d8153eebe92709545", "size": 539, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_39/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_39/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_39/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": 21.56, "max_line_length": 53, "alphanum_fraction": 0.4285714286, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95598134762883, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.823614453387664}} {"text": "module functions\nimplicit none\ninteger, parameter :: dp = kind(1.d0)\ncontains\n function heaviside(x)\n !=======================================================!\n ! Heaviside function !\n ! Daniel Celis Garza 15 Jan 2015 !\n !=======================================================!\n real(dp) :: heaviside, x\n heaviside = 0.0_dp\n if (x .ge. 0.0) heaviside = 1.0_dp\n end function heaviside\n\n function kdelta(i,j)\n !=======================================================!\n ! Kroencker delta function !\n ! Daniel Celis Garza 15 Jan 2015 !\n ! delta_ij !\n !=======================================================!\n integer i, j\n real(dp) kdelta\n kdelta = 0.0_dp\n if (i .eq. j) kdelta = 1.0_dp\n end function kdelta\nend module functions\n", "meta": {"hexsha": "87a7be593444938bb71e7b5aee5ab8585e0bef16", "size": 934, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "functions.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": "functions.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": "functions.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.5925925926, "max_line_length": 61, "alphanum_fraction": 0.3704496788, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8976952989498448, "lm_q1q2_score": 0.8234582913127093}} {"text": "program Arquimedes\n\n implicit none\n\n integer , parameter :: pr=kind(1.d0)\n\n real(pr), parameter :: pi = 4._pr *atan(1._pr )\n\n real(pr) :: a0 , b0 , a, b, pw\n\n integer(8) :: k\n\n character(len=150) :: titulo1, titulo2\n! ----------------------------------------------------------\n\n ! Arquímedes\n\n\n\n write (*,*) ' #################### Arquímedes ###################### '\n write (*,*) '################# Usando perímetros de polígonos regulares ##################'\n\n a0 = 2._pr* sqrt (3._pr)\n\n b0 = 3._pr\n\n titulo1 = ' lados a(n) b(n) pi &\n (a+b)/2 a(n)-b(n) pi-(a+b)/2'\n\n write(*,*) ''\n\n write (*,200) titulo1\n\n write (*, '(I9 ,4(2x,F19 .16) ,2x ,2(1x, E13 .6) )') (6), a0, b0, pi, a0-b0, (a0+b0)/2._pr, pi-((a0+b0)/2._pr)\n\n do k=1 ,20\n\n a = 2._pr*a0*b0 /( a0 + b0)\n\n b = sqrt (a*b0)\n\n\n\n\n write (*, '(I9 ,4(2x,F19 .16) ,2x ,2(1x, E13 .6) )') (6*2**k), a, b, pi, (a+b)/2._pr, a-b, pi-((a+b)/2._pr)\n\n a0 = a\n\n b0 = b\n\n enddo\n\n ! ----------------------------------------------------------\n\n ! Wallis\n\n write (*,*) ''\n\n write (*,*) ''\n\n write (*,*) ' ###################### Wallis ####################### '\n\n titulo2 = ' k pw pi &\n\n (pw - pi)'\n\n write (*,200) titulo2\n\n\n\n a = 1._pr\n\n do k =1,10**6\n\n a = a*(4*k**2) /(1._pr *(4*k**2 - 1))\n\n if (mod(k,10**5) == 0) then\n\n pw = 2._pr*a\n\n write(*,'(6x ,I9 ,2(4x,F19.16) ,4x, E16.9) ') k, pw , pi , (pw -pi)\n\n endif\n\n enddo\n\n\n\n 200 format (A)\n\n end program\n", "meta": {"hexsha": "abc7612133ec85fb729976884c23870c5a16de22", "size": 1673, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "G1e16/ArquiWall.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": "G1e16/ArquiWall.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": "G1e16/ArquiWall.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": 18.1847826087, "max_line_length": 113, "alphanum_fraction": 0.3436939629, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.8234119884988482}} {"text": "! Example program that computes pi in parallel\nprogram compute_pi\n\n use mpi\n \n implicit none\n\n integer :: error, num_procs, proc_id, points_per_proc, n, i, start, end\n real(kind=8) :: x, dx, pi_sum, pi_sum_proc\n\n real(kind=8), parameter :: pi = 3.1415926535897932384626433832795d0\n\n call mpi_init(error)\n call mpi_comm_size(MPI_COMM_WORLD, num_procs, error)\n call mpi_comm_rank(MPI_COMM_WORLD, proc_id, error)\n\n ! Proc 0 will ask the user for the number of points\n if (proc_id == 0) then\n print *, \"Using \",num_procs,\" processors\"\n print *, \"Input n ... \"\n read *, n\n end if\n\n ! Broadcast to all procs; everybody gets the value of n from proc 0\n call mpi_bcast(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, error)\n\n dx = 1.d0 / n\n\n ! Determine how many points to handle with each proc\n points_per_proc = (n + num_procs - 1) / num_procs\n ! Only print out the number of points per proc by process 0\n if (proc_id == 0) then \n print *, \"points_per_proc = \", points_per_proc\n end if\n\n ! Determine start and end index for this proc's points\n start = proc_id * points_per_proc + 1\n end = min((proc_id + 1) * points_per_proc, n)\n\n ! Diagnostic: tell the user which points will be handled by which proc\n print '(\"Process \",i2,\" will take i = \",i8,\" through i = \",i8)', &\n proc_id, start, end\n\n pi_sum_proc = 0.d0\n do i=start,end\n x = (i - 0.5d0) * dx\n pi_sum_proc = pi_sum_proc + 1.d0 / (1.d0 + x**2)\n enddo\n\n call MPI_REDUCE(pi_sum_proc, pi_sum, 1, MPI_DOUBLE_PRECISION, MPI_SUM, 0, &\n MPI_COMM_WORLD, error)\n\n if (proc_id == 0) then\n print *, \"The approximation to pi is \", 4.d0 * dx * pi_sum\n print *, \"Difference = \", abs(pi - 4.d0 * dx * pi_sum)\n endif\n\n call mpi_finalize(error)\n\nend program compute_pi", "meta": {"hexsha": "c4275aa0f244ea27fb7ae8d9deba09ff51dc393f", "size": 1877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/compute_pi.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/compute_pi.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/compute_pi.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": 31.2833333333, "max_line_length": 79, "alphanum_fraction": 0.6291955248, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8962513696696647, "lm_q1q2_score": 0.8231891687225056}} {"text": "module etox_module\ncontains\n elemental real function etox(x)\n implicit none\n real, intent(in) :: x\n real :: term\n integer :: nterm\n real, parameter :: tol = 1.e-6\n\n etox = 1.\n term = 1.\n nterm = 0\n do\n nterm = nterm+1\n term = (x/nterm)*term\n etox = etox+term\n if (term<=tol) exit\n end do\n end function\nend module\n\nprogram ch2606\n ! Elemental e**x Function\n use etox_module\n implicit none\n\n integer :: i\n real :: x\n real, dimension(1:10) :: y\n\n x = 1.\n do i = 1, 10\n y(i) = i\n end do\n print *, y\n x = etox(x)\n print *, x\n y = etox(y)\n print *, y\nend program\n", "meta": {"hexsha": "b3def810532bfc07192bf8ab3e92972d3fed1131", "size": 726, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch26/ch2606.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": "ch26/ch2606.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": "ch26/ch2606.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": 17.7073170732, "max_line_length": 38, "alphanum_fraction": 0.4848484848, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8231820387922121}} {"text": "module ran_mod \n! ran1 returns a uniform random number between 0-1\ncontains \n function ran1(my_seed)\n use numz\n implicit none\n real(b8) ran1,r\n integer, optional,intent(in) :: my_seed\n integer,allocatable :: seed(:)\n integer the_size,j\n if(present(my_seed))then ! use the seed if present\n call random_seed(size=the_size) ! how big is the seed?\n allocate(seed(the_size)) ! allocate space for seed\n do j=1,the_size\n seed(j)=abs(my_seed)+(j+1) ! create the seed\n enddo\n call random_seed(put=seed) ! assign the seed\n deallocate(seed) ! deallocate space \n endif\n call random_number(r)\n ran1=r\n end function ran1\n \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 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) \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\n\n", "meta": {"hexsha": "932d96a5e9ee461f4d67e41fdcbcff66d814c711", "size": 1796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fort/90/source/ran_mod.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": "fort/90/source/ran_mod.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": "fort/90/source/ran_mod.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": 28.0625, "max_line_length": 69, "alphanum_fraction": 0.5328507795, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.8231319316626696}} {"text": "! 4670 Numerical Analysis\n! Last Assignment Due 12.13.17\n\nprogram linsysmatocoefficients\n implicit none\n integer :: i, j, k, n\n double precision :: m, sum\n double precision, allocatable, dimension(:,:) :: a\n double precision, allocatable, dimension(:) :: b, x\n\n n = 5\n allocate(a(1:n,1:n),x(1:n), b(1:n))\n\n ! testing data when n = 5 (5 x 5 matrix)\n a(1,:) = (/ 5.0d0, 4.0d0, 6.0d0, 8.0d0, 1.0d0 /)\n a(2,:) = (/ 0.0d0, 3.0d0, 2.0d0, 3.0d0, 5.0d0 /)\n a(3,:) = (/ 0.0d0, 0.0d0, -7.0d0, 1.0d0, 9.0d0 /)\n a(4,:) = (/ 0.0d0, 0.0d0, 2.0d0, 1.0d0, 2.0d0 /)\n a(5,:) = (/ 0.0d0, 0.0d0, 0.0d0, 4.0d0, 5.0d0 /)\n b = (/ 7.0d0, -1.0d0, 1.0d0, 5.0d0, 4.0d0 /)\n\n do k = 1, (n - 1)\n do i = (k + 1), n\n m = a(i,k) / a(k,k)\n do j = k, n\n a(i,j) = a(i,j) - m * a(k,j)\n end do\n b(i) = b(i) - m * b(k)\n end do\n end do\n\n x(n) = b(n) / a(n,n)\n do i = (n - 1), 1, -1\n sum = 0.0d0\n do j = n, (i + 1), -1\n sum = (sum + (a(i,j) * x(j))) !top half\n end do\n x(i) = ((b(i) - sum) / a(i,i))\n end do\n\n print*, 'creating output file for Gaussian loop'\n open(unit=8, file='out1', status='replace')\n\n do i = 1, n\n write(8,*) i, ': ', x(i)\n end do\n\n close(8)\n deallocate(a, b, x)\n\n stop\nend program linsysmatocoefficients\n", "meta": {"hexsha": "1515fbcdb43245b0213854db109da82c14afb0ee", "size": 1264, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/HomeworkLast/finalQ1.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/HomeworkLast/finalQ1.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/HomeworkLast/finalQ1.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": 23.8490566038, "max_line_length": 53, "alphanum_fraction": 0.4984177215, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.8230125276753321}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Newton-Raphson para sistema de ecuaciones\n!Descripción: Programa que calcula las raíces de una sistema de ecuaciones no lineales\n!Fecha: 27/10/2018\n \n\nProgram newrap\n implicit none\n REAL::e, er, x, y, xe, u, v, pux, puy, pvx, pvy, J\n INTEGER::i\n WRITE(*, *) \"Valor inicial de x\" !Preguntar final del intervalo\n READ(*, *) x !Ingresar final del intervalo\n WRITE(*, *) \"Valor inicial de y\" !Preguntar final del intervalo\n READ(*, *) y !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 J=pux(x, y)*pvy(x, y)-puy(x, y)*pvx(x, y)\n x=x-(u(x, y)*pvy(x, y)-v(x, y)*puy(x, y))/J\n y=y-(v(x, y)*pux(x, y)-u(x, y)*pvx(x, y))/J\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 1.0D-35) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in case 2.'\n WRITE (KOUT,*) ' '\n ENDIF\n\n! 3. Sometimes we want to measure the errors using base 2 arithmetic in FM,\n! to more accurately reflect what is happening in the d.p. calculation.\n! Set FM to use base 2, and do the calculation with 53 bits of precision\n! (64-bit d.p.), then 73, 93, 113 bits.\n\n! We want exact control over the base and precision, so use FM_SETVAR\n! instead of FM_SET.\n\n! This shows a loss of 14 or 15 (base 10) digits when using base 2.\n\n! This is typical of the comparison between using FM with the default large base\n! and base 2. Normalization error is larger with a large base, but the 30 s.d.\n! calculation in case 2 gets about the same accuracy as the 113-bit calculation\n! in case 3, and using base 2 is much slower.\n\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' 3. Use FM with increasing precision in base 2.'\n WRITE (KOUT,*) ' '\n CALL FM_SETVAR(\" MBASE = 2 \")\n CALL FM_SETVAR(\" NDIG = 150 \")\n S2_FM = 0\n X_FM = 35.0D0/2\n X2_FM = -(X_FM**2)\n FACT_FM = 1\n DO K = 0, 700\n T_FM = X_FM / ( (K+1) * FACT_FM**2 )\n IF ( ABS(T_FM) < EPSILON(S2_FM)*ABS(S2_FM) ) EXIT\n S2_FM = S2_FM + T_FM\n X_FM = X_FM * X2_FM\n FACT_FM = FACT_FM * (K+1)\n ENDDO\n\n DO J = 53, 113, 20\n WRITE (STF,*) ' NDIG =',J\n CALL FM_SETVAR(TRIM(STF))\n S_FM = 0\n X_FM = 35.0D0/2\n X2_FM = -(X_FM**2)\n FACT_FM = 1\n DO K = 0, 700\n T_FM = X_FM / ( (K+1) * FACT_FM**2 )\n S_FM = S_FM + T_FM\n IF ( ABS(T_FM) < EPSILON(S_FM)*ABS(S_FM) ) THEN\n WRITE (STF,*) ' F',NINT(J*0.301)+3,'.',NINT(J*0.301)+1\n CALL FM_FORM(TRIM(STF),S_FM,ST1)\n WRITE (KOUT,\"(A,I3,A,I3,A,A)\") ' Using ',J,' bits,',K, &\n ' terms gave S_FM = ',TRIM(ST1)\n CALL FM_ULP(S_FM,T_FM)\n\n! Since S2_FM was computed at a different precision than S_FM, we should\n! round it to the current precision. For this case we have explicitly set\n! NDIG instead of using FM_SET as in case 2 above, so we use FM_EQU to do\n! the rounding.\n\n CALL FM_EQU(S2_FM,X2_FM,150,J)\n ERROR_FM = ABS( (S_FM-X2_FM)/T_FM )\n DIGITS_LOST_FM = NINT(LOG10(ERROR_FM))\n WRITE (KOUT,\"(A,I3,A)\") ' This calculation lost about ', &\n TO_INT(DIGITS_LOST_FM),' decimal digits.'\n EXIT\n ENDIF\n X_FM = X_FM * X2_FM\n FACT_FM = FACT_FM * (K+1)\n ENDDO\n ENDDO\n IF (ABS(S_FM-TO_FM('.0439909421796256399686302351876196')) > 1.0D-20) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in case 3.'\n WRITE (KOUT,*) ' '\n ENDIF\n\n! 4. A second way to check an algorithm's stability is to re-do the calculation\n! at the same precision but with different rounding modes.\n\n! Use base 2 with 53 bits and round down, then round symmetrically, then round up.\n\n! The results show the three values have no digits of agreement, confirming the\n! loss of about 15 or 16 s.d. in the ones rounded down and up.\n\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' 4. Use FM with different rounding modes in base 2.'\n WRITE (KOUT,*) ' '\n CALL FM_SETVAR(\" MBASE = 2 \")\n CALL FM_SETVAR(\" NDIG = 53 \")\n\n DO J = 1, 3\n IF (J == 1) THEN\n CALL FM_SETVAR(\" KROUND = -1 \")\n ELSE IF (J == 2) THEN\n CALL FM_SETVAR(\" KROUND = 1 \")\n ELSE IF (J == 3) THEN\n CALL FM_SETVAR(\" KROUND = 2 \")\n ENDIF\n S_FM = 0\n X_FM = 35.0D0/2\n X2_FM = -(X_FM**2)\n FACT_FM = 1\n DO K = 0, 700\n T_FM = X_FM / ( (K+1) * FACT_FM**2 )\n S_FM = S_FM + T_FM\n IF ( ABS(T_FM) < EPSILON(S_FM)*ABS(S_FM) ) THEN\n IF (J == 1) THEN\n STF = 'rounding left ,'\n ELSE IF (J == 2) THEN\n STF = 'rounding symmetrically,'\n ELSE IF (J == 3) THEN\n STF = 'rounding right ,'\n ENDIF\n CALL FM_FORM(' F20.17 ',S_FM,ST1)\n WRITE (KOUT,\"(A,I4,A,A,I3,A,A)\") ' Using',53,' bits, ',TRIM(STF),K, &\n ' terms gave S_FM = ',TRIM(ST1)\n EXIT\n ENDIF\n X_FM = X_FM * X2_FM\n FACT_FM = FACT_FM * (K+1)\n ENDDO\n R_FM(J) = S_FM\n ENDDO\n ERROR_FM = MAX( ABS((R_FM(1)-R_FM(2))/R_FM(1)) , ABS((R_FM(1)-R_FM(3))/R_FM(1)) , &\n ABS((R_FM(2)-R_FM(3))/R_FM(2)) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (KOUT,\"(A,I3,A)\") ' These agree to about',J,' decimal digits.'\n IF (ABS(S_FM-TO_FM('.0519420065663800')) > 1.0D-4) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in case 4.'\n WRITE (KOUT,*) ' '\n ENDIF\n\n! Use base 2 with 113 bits and round down, then round symmetrically, then round up.\n\n! Now the three values agree to about 18 decimal digits, which is again consistent\n! with a loss of about 15 or 16 s.d. in the ones rounded down and up.\n\n WRITE (KOUT,*) ' '\n CALL FM_SETVAR(\" MBASE = 2 \")\n CALL FM_SETVAR(\" NDIG = 113 \")\n\n DO J = 1, 3\n IF (J == 1) THEN\n CALL FM_SETVAR(\" KROUND = -1 \")\n ELSE IF (J == 2) THEN\n CALL FM_SETVAR(\" KROUND = 1 \")\n ELSE IF (J == 3) THEN\n CALL FM_SETVAR(\" KROUND = 2 \")\n ENDIF\n S_FM = 0\n X_FM = 35.0D0/2\n X2_FM = -(X_FM**2)\n FACT_FM = 1\n DO K = 0, 700\n T_FM = X_FM / ( (K+1) * FACT_FM**2 )\n S_FM = S_FM + T_FM\n IF ( ABS(T_FM) < EPSILON(S_FM)*ABS(S_FM) ) THEN\n IF (J == 1) THEN\n STF = 'rounding left ,'\n ELSE IF (J == 2) THEN\n STF = 'rounding symmetrically,'\n ELSE IF (J == 3) THEN\n STF = 'rounding right ,'\n ENDIF\n CALL FM_FORM(' F20.17 ',S_FM,ST1)\n WRITE (KOUT,\"(A,I4,A,A,I3,A,A)\") ' Using',113,' bits, ',TRIM(STF),K, &\n ' terms gave S_FM = ',TRIM(ST1)\n EXIT\n ENDIF\n X_FM = X_FM * X2_FM\n FACT_FM = FACT_FM * (K+1)\n ENDDO\n R_FM(J) = S_FM\n ENDDO\n ERROR_FM = MAX( ABS((R_FM(1)-R_FM(2))/R_FM(1)) , ABS((R_FM(1)-R_FM(3))/R_FM(1)) , &\n ABS((R_FM(2)-R_FM(3))/R_FM(2)) )\n J = -NINT(LOG10(ERROR_FM))\n WRITE (KOUT,\"(A,I3,A)\") ' These agree to about',J,' decimal digits.'\n IF (ABS(S_FM-TO_FM('.0439909421796257')) > 1.0D-4) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in case 4.'\n WRITE (KOUT,*) ' '\n ENDIF\n\n\n! 5. A third way to check an algorithm's stability is to re-do the calculation\n! at the same precision but using interval arithmetic.\n\n! Use base 2 with 53 bits.\n\n! The result shows the two endpoints of the interval having opposite signs\n! indicating a worst-case loss of all 16 s.d. during the calculation.\n\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' 5. Use FM with interval arithmetic in base 2.'\n WRITE (KOUT,*) ' '\n CALL FM_SETVAR(\" MBASE = 2 \")\n CALL FM_SETVAR(\" NDIG = 53 \")\n\n S_FM_INTERVAL = 0\n X_FM_INTERVAL = 35.0D0/2\n X2_FM_INTERVAL = -(X_FM_INTERVAL**2)\n FACT_FM_INTERVAL = 1\n DO K = 0, 700\n T_FM_INTERVAL = X_FM_INTERVAL / ( (K+1) * FACT_FM_INTERVAL**2 )\n S_FM_INTERVAL = S_FM_INTERVAL + T_FM_INTERVAL\n IF ( ABS(T_FM_INTERVAL) < EPSILON(S_FM_INTERVAL)*ABS(S_FM_INTERVAL) ) THEN\n CALL FM_INTERVAL_FORM(' F20.16 ',S_FM_INTERVAL,ST1)\n WRITE (KOUT,\"(A,I4,A,I3,A,A)\") ' Using',53,' bits, ',K, &\n ' terms gave S_FM_INTERVAL = ',TRIM(ST1)\n EXIT\n ENDIF\n X_FM_INTERVAL = X_FM_INTERVAL * X2_FM_INTERVAL\n FACT_FM_INTERVAL = FACT_FM_INTERVAL * (K+1)\n ENDDO\n ERROR_FM = ABS((RIGHT_ENDPOINT(S_FM_INTERVAL)-LEFT_ENDPOINT(S_FM_INTERVAL)) / &\n RIGHT_ENDPOINT(S_FM_INTERVAL))\n J = -NINT(LOG10(ERROR_FM))\n WRITE (KOUT,\"(A,I3,A)\") ' The two endpoints agree to about',J,' decimal digits.'\n\n! Use base 2 with 113 bits.\n\n! The result shows the two endpoints of the interval agree to about 18 s.d.\n! indicating a worst-case loss of about 16 s.d. during the calculation.\n\n WRITE (KOUT,*) ' '\n CALL FM_SETVAR(\" MBASE = 2 \")\n CALL FM_SETVAR(\" NDIG = 113 \")\n\n S_FM_INTERVAL = 0\n X_FM_INTERVAL = 35.0D0/2\n X2_FM_INTERVAL = -(X_FM_INTERVAL**2)\n FACT_FM_INTERVAL = 1\n DO K = 0, 700\n T_FM_INTERVAL = X_FM_INTERVAL / ( (K+1) * FACT_FM_INTERVAL**2 )\n S_FM_INTERVAL = S_FM_INTERVAL + T_FM_INTERVAL\n IF ( ABS(T_FM_INTERVAL) < EPSILON(S_FM_INTERVAL)*ABS(S_FM_INTERVAL) ) THEN\n CALL FM_INTERVAL_FORM(' F20.16 ',S_FM_INTERVAL,ST1)\n WRITE (KOUT,\"(A,I4,A,I3,A,A)\") ' Using',113,' bits, ',K, &\n ' terms gave S_FM_INTERVAL = ',TRIM(ST1)\n EXIT\n ENDIF\n X_FM_INTERVAL = X_FM_INTERVAL * X2_FM_INTERVAL\n FACT_FM_INTERVAL = FACT_FM_INTERVAL * (K+1)\n ENDDO\n ERROR_FM = ABS((RIGHT_ENDPOINT(S_FM_INTERVAL)-LEFT_ENDPOINT(S_FM_INTERVAL)) / &\n RIGHT_ENDPOINT(S_FM_INTERVAL))\n J = -NINT(LOG10(ERROR_FM))\n WRITE (KOUT,\"(A,I3,A)\") ' The two endpoints agree to about',J,' decimal digits.'\n IF (ABS(S_FM_INTERVAL-TO_FM('.0439909421796257')) > 1.0D-4) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in case 5.'\n WRITE (KOUT,*) ' '\n ENDIF\n\n\n IF (NERROR == 0) THEN\n WRITE (KOUT,\"(//A)\") ' Summary:'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' For this calculation all four methods for measuring the degree of'\n WRITE (KOUT,\"(A)\") ' instability worked well. When done with double precision carrying'\n WRITE (KOUT,\"(A)\") ' 16 significant digits and using the default symmetric rounding,'\n WRITE (KOUT,\"(A)\") ' only 1 digit remained correct at the end of the sum.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' Interval arithmetic is probably the strongest of these checks, and'\n WRITE (KOUT,\"(A)\") ' using FM arithmetic with 30 digits and a large base (method 2) is'\n WRITE (KOUT,\"(A)\") ' the fastest of these methods for getting the sum correct to full'\n WRITE (KOUT,\"(A)\") ' double precision accuracy.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' Comparing the last value of S in method 1 with the first value of'\n WRITE (KOUT,\"(A)\") ' S_FM in method 3 should show whether this compiler carries extra'\n WRITE (KOUT,\"(A)\") ' digits while evaluating expressions like X / ( (K+1) * FACT**2 ).'\n WRITE (KOUT,\"(A)\") ' If the two values are the same, no extra digits are carried in d.p.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' '\n ENDIF\n\n! -----------------------------------------------------------------------------------------Sample 2\n\n! Here is a recurrence that is seriously unstable.\n\n! It is not a realistic problem that would come up in a practical application, but\n! is designed as a counter-example to show that just carrying much higher precision\n! cannot be proved to always cure numerical instability.\n! Reference: William Kahan -- (2006)\n! \"How Futile are Mindless Assessments of Roundoff in Floating-Point Computation?\"\n! http://www.cs.berkeley.edu/~wkahan/Mindless.pdf\n\n! After 60 steps the result without any rounding errors would be very close to 5,\n! but rounding errors cause the result to converge to 100 instead.\n\n CALL FM_SET(30)\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Sample 2. Unstable recurrence.'\n WRITE (KOUT,*) ' '\n WRITE (KOUT,\"(A)\") ' 1. Use non-interval FM arithmetic with 30 digits.'\n WRITE (KOUT,*) ' '\n X_FM = 4\n X2_FM = TO_FM('4.25')\n DO J = 1, 60\n T_FM = 108 - ( 815 - 1500/X_FM ) / X2_FM\n X_FM = X2_FM\n X2_FM = T_FM\n IF (MOD(J,5) == 0) THEN\n CALL FM_FORM(' F20.14 ',X2_FM,ST1)\n WRITE (KOUT,\"(A,I2,A,A)\") ' After ',J, &\n ' terms with 30 digit accuracy, the result is',TRIM(ST1)\n ENDIF\n ENDDO\n WRITE (KOUT,*) ' '\n\n WRITE (KOUT,\"(A)\") ' 2. Use interval arithmetic with 30 digit accuracy.'\n WRITE (KOUT,*) ' '\n X_FM_INTERVAL = 4\n X2_FM_INTERVAL = TO_FM_INTERVAL('4.25')\n DO J = 1, 60\n T_FM_INTERVAL = 108 - ( 815 - 1500/X_FM_INTERVAL ) / X2_FM_INTERVAL\n X_FM_INTERVAL = X2_FM_INTERVAL\n X2_FM_INTERVAL = T_FM_INTERVAL\n CALL FM_INTERVAL_FORM(' F20.16 ',X2_FM_INTERVAL,ST1)\n WRITE (KOUT,\"(A,I3,A,A)\") ' After',J,' terms the result is',TRIM(ST1)\n IF (LEFT_ENDPOINT(X_FM_INTERVAL) <= 0 .AND. RIGHT_ENDPOINT(X_FM_INTERVAL) >= 0) EXIT\n IF (J > 10 .AND. J < 25) THEN\n IF (ABS(LEFT_ENDPOINT(X2_FM_INTERVAL)-5) > 0.01 .OR. &\n ABS(RIGHT_ENDPOINT(X2_FM_INTERVAL)-5) > 0.01) THEN\n NERROR = NERROR + 1\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Error in sample 2, case 2.'\n WRITE (KOUT,*) ' '\n EXIT\n ENDIF\n ENDIF\n ENDDO\n\n IF (NERROR == 0) THEN\n WRITE (KOUT,\"(//A)\") ' Summary:'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' The general solution of this recurrence has a term that causes'\n WRITE (KOUT,\"(A)\") ' the values to converge to 100, but for these initial conditions'\n WRITE (KOUT,\"(A)\") ' 4, 4.25, the specific solution has a coefficient of zero on that'\n WRITE (KOUT,\"(A)\") ' term, so this sequence converges to 5 mathematically.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' When rounding errors occur in later x-values, they introduce a'\n WRITE (KOUT,\"(A)\") ' very small but nonzero amount of the term that causes convergence'\n WRITE (KOUT,\"(A)\") ' to 100, and that term grows rapidly and soon swamps the rest of'\n WRITE (KOUT,\"(A)\") ' the solution.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' Interval arithmetic tracks the growing uncertainty in the x-values,'\n WRITE (KOUT,\"(A)\") ' and when an interval gets big enough to include zero, dividing by'\n WRITE (KOUT,\"(A)\") ' that interval is undefined and the result is'\n WRITE (KOUT,\"(A)\") ' [ -overflow , +overflow ].'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' Interval arithmetic works better than a sequence of increasing'\n WRITE (KOUT,\"(A)\") ' precision FM results here, since comparing FM results at 30, 40, 50'\n WRITE (KOUT,\"(A)\") ' digits gives 100 each time.'\n WRITE (KOUT,\"(A)\") ' '\n ENDIF\n\n! -----------------------------------------------------------------------------------------Sample 3\n\n! Sum an unstable series.\n! exp(x) = 1 + x + x**2/2! + x**3/3! + ...\n! converges mathematically for all x, but is unstable for negative x.\n\n S_FM_INTERVAL = 1\n T_FM_INTERVAL = 1\n R_FM = (/ -25, -30, -35 /)\n EXP_SUM_INTERVAL = EXP_SUM3(R_FM)\n E = (/ -12, -9, -3 /)\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' '\n WRITE (KOUT,*) ' Sample 3. Unstable sum.'\n DO J = 1, 3\n CALL FM_INTERVAL_FORM(' ES25.16 ',EXP_SUM_INTERVAL(J),ST1)\n CALL FM_FORM(' ES25.16 ',EXP(R_FM(J)),STF)\n WRITE (KOUT,\"(/A,F6.2,A,A)\") ' For x = ', TO_DP(R_FM(J)), ' The sum gave ', ST1\n WRITE (KOUT,\"(20X,A,A)\") ' correct = ', STF\n\n! Check the results.\n\n X_FM = LEFT_ENDPOINT(EXP_SUM_INTERVAL(J))\n X2_FM = RIGHT_ENDPOINT(EXP_SUM_INTERVAL(J))\n S_FM = EXP(R_FM(J))\n T_FM = ABS( (X2_FM - X_FM ) / S_FM )\n IF (.NOT.(S_FM > X_FM) .OR. .NOT.(S_FM < X2_FM) .OR. .NOT.(T_FM < TO_FM(10)**E(J))) THEN\n NERROR = NERROR + 1\n EXIT\n ENDIF\n ENDDO\n\n IF (NERROR == 0) THEN\n WRITE (KOUT,\"(//A)\") ' Summary:'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' As the input x becomes more negative, the instability increases.'\n WRITE (KOUT,\"(A)\") ' This is shown as the left and right endpoints of the interval'\n WRITE (KOUT,\"(A)\") ' result agree to fewer digits.'\n WRITE (KOUT,\"(A)\") ' '\n WRITE (KOUT,\"(A)\") ' The mathematically correct value of the sum lies within the'\n WRITE (KOUT,\"(A)\") ' interval in each case.'\n WRITE (KOUT,\"(A)\") ' '\n ENDIF\n\n\n\n IF (NERROR == 0) THEN\n WRITE (* ,\"(//A,A/)\") ' All results were ok. (The output is in file ', &\n 'SampleFMinterval.out)'\n WRITE (KOUT,\"(//A/)\") ' All results were ok.'\n ELSE\n WRITE (* ,\"(//I3,A,A/)\") NERROR,' error(s) found. (The output is in file ', &\n 'SampleFMinterval.out)'\n WRITE (KOUT,\"(//I3,A/)\") NERROR,' error(s) found.'\n ENDIF\n\n STOP\n END PROGRAM TEST\n\n SUBROUTINE ROUND_FM(A,B,J1,J2)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! A was computed with precision defined by CALL FM_SET(J1).\n! B will be returned with the value of A rounded to precision defined by CALL FM_SET(J2).\n! Do not use B in the calling program at any precision higher than J2.\n\n TYPE (FM) :: A, B\n INTEGER :: J1, J2, NDIG1, NDIG2, NSAVE\n\n NSAVE = NDIG\n CALL FM_SET(J1)\n NDIG1 = NDIG\n CALL FM_SET(J2)\n NDIG2 = NDIG\n CALL FM_EQU(A,B,NDIG1,NDIG2)\n NDIG = NSAVE\n\n END SUBROUTINE ROUND_FM\n", "meta": {"hexsha": "9d5d323d8e14b57a97b5a569b9def88c757ae085", "size": 27528, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMinterval/SampleFMinterval.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/SampleFMinterval.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/SampleFMinterval.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": 42.156202144, "max_line_length": 100, "alphanum_fraction": 0.5281894798, "num_tokens": 7814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8991213671331905, "lm_q1q2_score": 0.8226069911859871}} {"text": "program secant\nuse funcs\nimplicit none\n\nreal(kind=8) :: x1, x2, x3, Er, true_x\nreal(kind=8) :: TrueError, TrueRelativeError, Tolerance\ninteger :: i, itermax\n\nitermax = 10 \ntrue_x = 1.232244855100926\n\nx1 = 1.0\nx2 = 1.5\nx3 = 0.0\n\nwrite(*,'(A7,F12.7,A10,F12.7)') \" x1: \", x1, \" f(x1): \", f(x1)\nwrite(*,'(A7,F12.7,A10,F12.7)') \" x2: \", x2, \" f(x2): \", f(x2)\nwrite(*,*)\nwrite(*,*) \"iteration x f(x) Err\"\n\ni = 1\nEr = 1\ndo while (Er > 0.0001)\n ! determine the new x and the error:\n x3 = x2 - (f(x2)*(x1-x2))/(f(x1)-f(x2))\n Er = dabs( (x3-x2) / x2)\n write(*,'(A2,I2,A2,3F12.7)') \" \", i, \" \", x3, f(x3), Er\n\n ! check if the maximum number of iterations has been exceeded:\n i = i+1 \n if (i > itermax) then\n write(*,*) \"The maximum number of iterations has been exceeded.\"\n exit\n end if\n\n x1 = x2\n x2 = x3\nend do\nwrite(*,*)\n\nTrueError = true_x - x3\nwrite(*,*) \"TrueError:\", TrueError\n\nTrueRelativeError = dabs( (true_x-x3) / true_x )*100\nwrite(*,*) \"TrueRelativeError:\", TrueRelativeError\n\nTolerance = dabs(f(x3))\nwrite(*,*) \"Tolerance:\", Tolerance\n\nend program secant\n", "meta": {"hexsha": "b09f40efe1d3dcc72a3a328d67ec8d47aa1d2d85", "size": 1112, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex2/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/HW4/ex2/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/HW4/ex2/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": 21.8039215686, "max_line_length": 70, "alphanum_fraction": 0.5863309353, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.8918110432813419, "lm_q1q2_score": 0.8221800733659301}} {"text": "\nprogram newton_raphson\n ! Program to compute approximate roots of polynomials using Newton-Raphson method of iterations.\n ! Author: Devansh Shukla\n\n implicit none\n integer :: j, m=1, n=1, big=0, iterations=50\n real :: x, i, h, f, df, f_value, old_f_value, initial_counter=-100, final_counter=100, guess_increment=0.5, tolerance=0.001\n real, dimension(10) :: guesses, roots\n\n ! M1 (a) (i)\n ! f(x) = x**3 - 3*x**2 + 2*x - 1\n ! df(x) = 3*x**2 - 6*x + 2\n\n ! M1 (a) (ii)\n ! f(x) = -2*x**2 + 3*x + 2\n ! df(x) = -4*x + 3\n\n ! M1 (b)\n ! f(x) = x**3 - 9*x**2 + 28.6479\n ! df(x) = 3*x**2 - 18*x\n\n ! Computing initial guess(es)\n print *,\"----------------------------------------------------\"\n print *, \"Computing inital guesses\"\n i = initial_counter\n old_f_value = f(i)\n10 i = i + guess_increment\n f_value = f(i)\n if (f_value <= 0 .and. old_f_value >= 0) then\n guesses(n) = i\n n = n + 1\n print \"(xxxx, F10.4, x, F10.6, x, F10.6)\", i, f_value, old_f_value\n elseif (f_value >= 0 .and. old_f_value <= 0) then\n guesses(n) = i\n n = n + 1\n print \"(xxxx, F10.4, x, F10.6, x, F10.6)\", i, f_value, old_f_value\n endif\n if (i=0.\r\n!---\r\nREAL :: a, sqrt, diff\r\ndiff = .001\r\nPRINT *, 'Approximates the square root of a to a default precision of:', diff\r\nDO\r\n\tPRINT *, 'Enter a (Enter a negative value to stop.)'\r\n READ *, a\r\n IF (a .lt. 0) STOP \r\n\tsqrt = mysqrt(a, diff)\r\n PRINT *, 'a:', a, ' sqrt(a):', sqrt\r\nEND DO\r\n\r\nCONTAINS\r\nREAL FUNCTION mysqrt(a, diff)\r\n\tREAL :: x0, x1\r\n x0 = a/2\r\n x1 = (x0 + a/x0)/2\r\n PRINT *, x0, x1\r\n DO WHILE (abs(x0 - x1) .gt. diff)\r\n\t\tx0 = x1\r\n \tx1 = (x0 + a/x0)/2\r\n\t\tPRINT *, x0, x1\r\n END DO\r\n mysqrt = x1\r\n\r\nEND FUNCTION mysqrt\r\nEND PROGRAM A2Q2", "meta": {"hexsha": "06240c14286f0b23dc2aa2af07b4d24fbc8fa54b", "size": 661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 2/A2Q2.f90", "max_stars_repo_name": "Chris-Drury/COMP3731", "max_stars_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 2/A2Q2.f90", "max_issues_repo_name": "Chris-Drury/COMP3731", "max_issues_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 2/A2Q2.f90", "max_forks_repo_name": "Chris-Drury/COMP3731", "max_forks_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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.0333333333, "max_line_length": 78, "alphanum_fraction": 0.5627836611, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653855, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.8219977847124825}} {"text": "MODULE trig\nIMPLICIT NONE\nREAL, PARAMETER :: PI = 3.141592\nCONTAINS\n ELEMENTAL REAL FUNCTION sine_degrees(a)\n REAL, INTENT(IN) :: a\n sine_degrees = SIN(a * PI / 180.)\n END FUNCTION sine_degrees\n\n ELEMENTAL REAL FUNCTION cosine_degrees(a)\n REAL, INTENT(IN) :: a\n cosine_degrees = COS(a * PI / 180.)\n END FUNCTION cosine_degrees\n\n ELEMENTAL REAL FUNCTION tangent_degrees(a)\n REAL, INTENT(IN) :: a\n tangent_degrees = TAN(a * PI / 180.)\n END FUNCTION tangent_degrees\nEND MODULE trig\n\nPROGRAM elem_trig\nUSE trig\nIMPLICIT NONE\nREAL, DIMENSION(3,3) :: x\nINTEGER :: i, j\nx = RESHAPE([85.,45.,30.,60.,60.,-85.,0.,45.,-30.], SHAPE(x))\nWRITE(*, *) 'INPUT (DEGREES)'\nWRITE(*, '(3F9.4)') ((x(i, j), i = 1, 3), j = 1, 3)\nWRITE(*, *) 'SINE'\nWRITE(*, '(3F9.4)') ((sine_degrees(x(i, j)), i = 1, 3), j = 1, 3)\nWRITE(*, *) 'COSINE'\nWRITE(*, '(3F9.4)') ((cosine_degrees(x(i, j)), i = 1, 3), j = 1, 3)\nWRITE(*, *) 'TANGENT'\nWRITE(*, '(3F9.4)') ((tangent_degrees(x(i, j)), i = 1, 3), j = 1, 3)\nEND PROGRAM elem_trig\n", "meta": {"hexsha": "92f616f9b18c34491e6c1b2d2258c42e715fa367", "size": 1006, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap9/elem_trig.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/elem_trig.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/elem_trig.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.9444444444, "max_line_length": 68, "alphanum_fraction": 0.6212723658, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951863227517834, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.8218307211355856}} {"text": "! coordinates.f90 --\n! Straightforward module for coordinates transformations:\n! - spherical to cartesian and back\n! - cylindrical to cartesian and back\n! - polar to cartesian and back\n!\n! $Id$\n!\nmodule m_coordinates\n implicit none\n\ncontains\n\nsubroutine spherical_to_cart( rad, phi, theta, x, y, z )\n real, intent(in) :: rad, phi, theta\n real, intent(out) :: x, y, z\n\n x = rad * cos(phi) * cos(theta)\n y = rad * sin(phi) * cos(theta)\n z = rad * sin(theta)\n\nend subroutine spherical_to_cart\n\nsubroutine cart_to_spherical( x, y, z, rad, phi, theta )\n real, intent(in) :: x, y, z\n real, intent(out) :: rad, phi, theta\n\n rad = sqrt( x ** 2 + y ** 2 + z ** 2 )\n theta = asin(z/rad)\n if ( x /= 0.0 .or. y /= 0.0 ) then\n phi = atan2(y,x)\n else\n phi = 0.0\n endif\n\nend subroutine cart_to_spherical\n\nsubroutine cylindrical_to_cart( rad, phi, zin, x, y, z )\n real, intent(in) :: rad, phi, zin\n real, intent(out) :: x, y, z\n\n\n x = rad * cos(phi)\n y = rad * sin(phi)\n z = zin\n\nend subroutine cylindrical_to_cart\n\nsubroutine cart_to_cylindrical( x, y, z, rad, phi, zout )\n real, intent(in) :: x, y, z\n real, intent(out) :: rad, phi, zout\n\n rad = sqrt( x ** 2 + y ** 2 )\n if ( x /= 0.0 .or. y /= 0.0 ) then\n phi = atan2(y,x)\n else\n phi = 0.0\n endif\n zout = z\n\nend subroutine cart_to_cylindrical\n\nsubroutine polar_to_cart( rad, phi, x, y )\n real, intent(in) :: rad, phi\n real, intent(out) :: x, y\n\n\n x = rad * cos(phi)\n y = rad * sin(phi)\n\nend subroutine polar_to_cart\n\nsubroutine cart_to_polar( x, y, rad, phi )\n real, intent(in) :: x, y\n real, intent(out) :: rad, phi\n\n rad = sqrt( x ** 2 + y ** 2 )\n if ( x /= 0.0 .or. y /= 0.0 ) then\n phi = atan2(y,x)\n else\n phi = 0.0\n endif\n\nend subroutine cart_to_polar\n\nend module m_coordinates\n", "meta": {"hexsha": "2b276880889015e1b850627082e5d3dd589b0d64", "size": 1905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/computing/m_coordinates.f90", "max_stars_repo_name": "timcera/flibs", "max_stars_repo_head_hexsha": "c068043eb20391adf649ed8cf34d87a0797ae3cc", "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": "src/computing/m_coordinates.f90", "max_issues_repo_name": "timcera/flibs", "max_issues_repo_head_hexsha": "c068043eb20391adf649ed8cf34d87a0797ae3cc", "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/computing/m_coordinates.f90", "max_forks_repo_name": "timcera/flibs", "max_forks_repo_head_hexsha": "c068043eb20391adf649ed8cf34d87a0797ae3cc", "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": 21.8965517241, "max_line_length": 61, "alphanum_fraction": 0.5706036745, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8757869900269366, "lm_q1q2_score": 0.8215968037049497}} {"text": "program main \n use std \n implicit none \n real(real64) :: x(3) \n real(real64) :: A(3,3) \n real(real64) :: b(3)\n A(1,1)=5.0d0 ; A(1,2)=-2.0d0 ; A(1,3)=5.0d0 ; \n A(2,1)=4.4d0 ; A(2,2)=2.0d0 ; A(2,3)=20.0d0 ; \n A(3,1)=-9.0d0; A(3,2)=-8.0d0 ; A(3,3)=1.0d0 ; \n b(1) = 1.0d0 \n b(2) = 8.0d0 \n b(3) =-1.0d0 \n x(:)=0.0d0\n call gauss_jordan_pv(A, x, b, size(x) )\n call showArray(x)\n print *, \"ERROR is ::\",sqrt(dot_product(matmul(A,x)-b,matmul(A,x)-b))\nend program main", "meta": {"hexsha": "5b58ecb7acfa8de6ca19c7e0c08e930a07e97bb1", "size": 509, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/app/run/SolveEquations_ex1.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/app/regacy/run/SolveEquations_ex1.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/app/regacy/run/SolveEquations_ex1.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": 29.9411764706, "max_line_length": 73, "alphanum_fraction": 0.4970530452, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214491222695, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.8215563678275192}} {"text": "! Write a program that finds the summation of every number from 1 to num. The \n! number will always be a positive integer greater than 0.\n\nmodule Solution\n implicit none\ncontains\n integer pure function summation(n) result (res)\n integer, intent(in) :: n\n res = n * (n + 1) / 2 ! your code here\n end function summation\nend module Solution", "meta": {"hexsha": "aff7f85a372c8f9732297b3e26fe2ec26b2bd64d", "size": 346, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CodeWars/Grasshoper Summation.f90", "max_stars_repo_name": "lcols19/Algorithm_Solving", "max_stars_repo_head_hexsha": "2e4c174b1cd4374910038e7ffbc8a52a09ebe2b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CodeWars/Grasshoper Summation.f90", "max_issues_repo_name": "lcols19/Algorithm_Solving", "max_issues_repo_head_hexsha": "2e4c174b1cd4374910038e7ffbc8a52a09ebe2b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CodeWars/Grasshoper Summation.f90", "max_forks_repo_name": "lcols19/Algorithm_Solving", "max_forks_repo_head_hexsha": "2e4c174b1cd4374910038e7ffbc8a52a09ebe2b8", "max_forks_repo_licenses": ["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.4545454545, "max_line_length": 78, "alphanum_fraction": 0.7225433526, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9643214460461698, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.8215563615819974}} {"text": "PROGRAM A8Q1\r\n!---\r\n!Determines the GCD of a sequence of ints a and b given that a > b and a != 0. This program uses recusrion \r\n!---\r\nIMPLICIT NONE\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: MandNs, results\r\nINTEGER :: a, b, n, check, i\r\n\r\nPRINT *, \"This program determines the GCD of a sequence through iteration.\"\r\nDO\r\n \tPRINT *, \"Enter the size of the integer sequence (0 to stop)\"\r\n READ *, n\r\n IF (n .eq. 0) STOP\r\n ALLOCATE(MandNs(n), results(n-1), STAT=check)\r\n IF (check .ne. 0) THEN\r\n \tPRINT *, \"Array allocation unsuccessful, please try again\"\r\n\tELSE\r\n \tPRINT *, \"Please enter the integer sequence:\"\r\n\t\tREAD *, MandNs\r\n PRINT *, 'GCDs: '\r\n DO i = 1,n-1\r\n \ta = MandNs(i)\r\n b = MandNs(i + 1)\r\n MandNs(i) = 0\r\n IF (a .eq. 0 .and. b .eq. 0) STOP\r\n \t\tIF (a .eq. 0) THEN\r\n \t\t\tMandNs(i+1) = b\r\n \t\t\tELSE IF (b .eq. 0) THEN\r\n \t\t\tMandNs(i+1) = a\r\n \t\tELSE\r\n \t\t\tMandNs(i+1) = GCD(a,b)\r\n \t\tEND IF\r\n PRINT *, MandNs\r\n END DO\r\n PRINT *, \"Final GCD: \", MandNs(n)\r\n\tEND IF\r\n DEALLOCATE(MandNs, results)\r\nEND DO\r\n\r\nCONTAINS\r\nINTEGER RECURSIVE FUNCTION GCD(m,n) RESULT(g)\r\n\tINTEGER, INTENT(IN) :: m, n\r\n \r\n\tIF (n .gt. m) THEN\r\n \tg = GCD(n, m)\r\n ELSE IF (n .eq. 0) THEN\r\n \tg = m\r\n ELSE IF (m .gt. n .and. n .gt. 0) THEN\r\n \tg = GCD(n, mod(m,n))\r\n\tEND IF\r\n\r\nEND FUNCTION GCD\r\nEND PROGRAM A8Q1\r\n", "meta": {"hexsha": "a6c23ec796b2554368c435a42b06334eec6ba66b", "size": 1431, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 8/A8Q1.f90", "max_stars_repo_name": "Chris-Drury/COMP3731", "max_stars_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 8/A8Q1.f90", "max_issues_repo_name": "Chris-Drury/COMP3731", "max_issues_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": "Assignment 8/A8Q1.f90", "max_forks_repo_name": "Chris-Drury/COMP3731", "max_forks_repo_head_hexsha": "59d70f4fe8354b7b50fd2911ec2d8e7aad8401bc", "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": 26.5, "max_line_length": 108, "alphanum_fraction": 0.534591195, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075777163566, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.8215559356887303}} {"text": "! ============================================================================\n! Name : mo_eq_lv.f90\n! Author : Giovanni Dalmasso\n! Version : 1.0\n! Copyright : Department of Computational Hydrosystems CHS - UZF Leipzig\n! Description : Lotka Volterra equations\n! ============================================================================\n\nmodule mo_eq_lv\n\n ! ------------------------------------------------------------------\n ! The Lotka Volterra equations, also known as the predator-prey equations, are a pair of first-order, non-linear,\n ! differential equations frequently used to describe the dynamics of biological systems in which two species interact,\n ! one a predator and one its prey. They evolve in time according to the following of equations\n ! ------------------------------------------------------------------\n\n implicit none\n\n private\n\n public :: LV_eqn, LV_eqn_sp, LV_eqn_dp, &\n LV_eqn_para, LV_eqn_para_sp, LV_eqn_para_dp, &\n deriv_testRB_sp, jacobn_testRB_sp, &\n deriv_testRB_dp, jacobn_testRB_dp, &\n deriv2_testRB_sp, jacobn2_testRB_sp, &\n deriv2_testRB_dp, jacobn2_testRB_dp, &\n deriv2_testRB_para_sp, jacobn2_testRB_para_sp, &\n deriv2_testRB_para_dp, jacobn2_testRB_para_dp\n\n\n ! Interfaces for single and double precision routines\n interface LV_eqn\n module procedure LV_eqn_sp, LV_eqn_dp\n end interface\n\n interface LV_eqn_para\n module procedure LV_eqn_para_sp, LV_eqn_para_dp\n end interface\n\ncontains\n\n ! SINGLE PRECISION\n subroutine LV_eqn_sp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(sp), parameter :: epsilonn = 0.5_sp ! regulates the relationship between the two species\n ! keeping the optimum balance\n\n real(sp), parameter :: mu = 2._sp ! represents the ability to reproduce of the first species\n ! with respect to the destructive capacity of the second one\n\n real(sp), parameter :: eta = -1._sp ! regulates the relationship between the influences of nutrition\n ! related reproductive capacity\n\n ! ============================================================================\n ! System of ODE\n !\n ! y(1) --> predators\n ! y(2) --> preys\n ! does not depend on time --> 0.0 * x (to avoid warnings of unused variables)\n ! ============================================================================\n\n dydx(1) = y(1) - epsilonn*mu*y(2) + 0.0_sp*x\n dydx(2) = (mu/epsilonn)*y(1) + eta*y(2) + 0.0_sp*x\n\n end subroutine LV_eqn_sp\n\n ! DOUBLE PRECISION\n subroutine LV_eqn_dp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(dp), parameter :: epsilonn = 0.5_dp ! regulates the relationship between the two species\n ! keeping the optimum balance\n\n real(dp), parameter :: mu = 2._dp ! represents the ability to reproduce of the first species\n ! with respect to the destructive capacity of the second one\n\n real(dp), parameter :: eta = -1._dp ! regulates the relationship between the influences of nutrition\n ! related reproductive capacity\n\n ! ============================================================================\n ! System of ODE\n !\n ! y(1) --> predators\n ! y(2) --> preys\n ! does not depend on time --> 0.0 * x (to avoid warnings of unused variables)\n ! ============================================================================\n\n dydx(1) = y(1) - epsilonn*mu*y(2) + 0.0_dp*x\n dydx(2) = (mu/epsilonn)*y(1) + eta*y(2) + 0.0_dp*x\n\n end subroutine LV_eqn_dp\n\n!-----------\n! with parameter input\n!-----------\n\n ! SINGLE PRECISION\n subroutine LV_eqn_para_sp( x, y, para, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(sp), dimension(:), intent(in) :: para ! parameter\n\n! real(sp), parameter :: epsilonn = 0.5_sp ! regulates the relationship between the two species\n! ! keeping the optimum balance\n\n! real(sp), parameter :: mu = 2._sp ! represents the ability to reproduce of the first species\n! ! with respect to the destructive capacity of the second one\n\n! real(sp), parameter :: eta = -1._sp ! regulates the relationship between the influences of nutrition\n! ! related reproductive capacity\n\n ! ============================================================================\n ! System of ODE\n !\n ! y(1) --> predators\n ! y(2) --> preys\n ! does not depend on time --> 0.0 * x (to avoid warnings of unused variables)\n ! ============================================================================\n\n dydx(1) = y(1) - para(1)*para(2)*y(2) + 0.0_sp*x\n dydx(2) = (para(2)/para(1))*y(1) + para(3)*y(2) + 0.0_sp*x\n\n end subroutine LV_eqn_para_sp\n\n ! DOUBLE PRECISION\n subroutine LV_eqn_para_dp( x, y, para, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(dp), dimension(:), intent(in) :: para ! parameter\n\n! real(dp), parameter :: epsilonn = 0.5_dp ! regulates the relationship between the two species\n! ! keeping the optimum balance\n\n! real(dp), parameter :: mu = 2._dp ! represents the ability to reproduce of the first species\n! ! with respect to the destructive capacity of the second one\n\n! real(dp), parameter :: eta = -1._dp ! regulates the relationship between the influences of nutrition\n! ! related reproductive capacity\n\n ! ============================================================================\n ! System of ODE\n !\n ! y(1) --> predators\n ! y(2) --> preys\n ! does not depend on time --> 0.0 * x (to avoid warnings of unused variables)\n ! ============================================================================\n\n dydx(1) = y(1) - para(1)*para(2)*y(2) + 0.0_dp*x\n dydx(2) = (para(2)/para(1))*y(1) + para(3)*y(2) + 0.0_dp*x\n\n end subroutine LV_eqn_para_dp\n\n\n!-----------\n! stiff sets of ODEs\n!-----------\n\n!SINGLE PRECISION\n subroutine deriv_testRB_sp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(sp) :: xtmp\n\n xtmp = x\n\n dydx(1) = 998.0_sp*y(1) + 1998.0_sp*y(2)\n dydx(2) = -999.0_sp*y(1)- 1999.0_sp*y(2)\n\n end subroutine deriv_testRB_sp\n\n subroutine jacobn_testRB_sp( x, y, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(sp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(sp) :: xtmp\n real(sp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_sp\n dfdx(2) = 0.0_sp\n\n dfdy(1,1) = 998.0_sp\n dfdy(1,2) = 1998.0_sp\n dfdy(2,1) = -999.0_sp\n dfdy(2,2) = 1999.0_sp\n\n end subroutine jacobn_testRB_sp\n\n subroutine deriv2_testRB_sp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(sp) :: xtmp\n\n xtmp = x\n\n dydx(1) = (-0.013_sp-1000.0_sp*y(3))*y(1)\n dydx(2) = -2500.0_sp*y(3)*y(2)\n dydx(3) = -0.013_sp*y(1) + (-1000.0_sp*y(1)-2500.0_sp*y(2))*y(3)\n\n end subroutine deriv2_testRB_sp\n\n subroutine jacobn2_testRB_sp( x, y, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(sp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(sp) :: xtmp\n real(sp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_sp\n dfdx(2) = 0.0_sp\n dfdx(3) = 0.0_sp\n\n dfdy(1,1) = -0.013_sp-1000.0_sp*y(3)\n dfdy(1,2) = 0.0_sp\n dfdy(1,3) = -1000.0_sp*y(1)\n dfdy(2,1) = 0.0_sp\n dfdy(2,2) = -2500.0_sp*y(3)\n dfdy(2,3) = -2500.0_sp*y(2)\n dfdy(3,1) = -0.013_sp-1000.0_sp*y(3)\n dfdy(3,2) = -2500.0_sp*y(3)\n dfdy(3,3) = -1000.0_sp*y(1)-2500.0_sp*y(2)\n\n end subroutine jacobn2_testRB_sp\n\n subroutine deriv2_testRB_para_sp( x, y, para, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(sp), dimension(:), intent(in) :: para ! parameter\n\n real(sp) :: xtmp\n\n xtmp = x\n\n\n dydx(1) = (-0.013_sp-para(1)*y(3))*y(1)\n dydx(2) = -2500.0_sp*y(3)*y(2)\n dydx(3) = -0.013_sp*y(1) + (-1000.0_sp*y(1)-2500.0_sp*y(2))*y(3)\n\n end subroutine deriv2_testRB_para_sp\n\n subroutine jacobn2_testRB_para_sp( x, y, para, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : sp\n\n implicit none\n\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(sp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(sp), dimension(:), intent(in) :: para ! parameter\n\n real(sp) :: xtmp\n real(sp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_sp\n dfdx(2) = 0.0_sp\n dfdx(3) = 0.0_sp\n\n dfdy(1,1) = -0.013_sp-para(1)*y(3)\n dfdy(1,2) = 0.0_sp\n dfdy(1,3) = -1000.0_sp*y(1)\n dfdy(2,1) = 0.0_sp\n dfdy(2,2) = -2500.0_sp*y(3)\n dfdy(2,3) = -2500.0_sp*y(2)\n dfdy(3,1) = -0.013_sp-1000.0_sp*y(3)\n dfdy(3,2) = -2500.0_sp*y(3)\n dfdy(3,3) = -1000.0_sp*y(1)-2500.0_sp*y(2)\n\n end subroutine jacobn2_testRB_para_sp\n\n!DOUBLE PRECISION\n subroutine deriv_testRB_dp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(dp) :: xtmp\n\n xtmp = x\n\n dydx(1) = 998.0_dp*y(1) + 1998.0_dp*y(2)\n dydx(2) = -999.0_dp*y(1)- 1999.0_dp*y(2)\n\n end subroutine deriv_testRB_dp\n\n subroutine jacobn_testRB_dp( x, y, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(dp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(dp) :: xtmp\n real(dp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_dp\n dfdx(2) = 0.0_dp\n\n dfdy(1,1) = 998.0_dp\n dfdy(1,2) = 1998.0_dp\n dfdy(2,1) = -999.0_dp\n dfdy(2,2) = 1999.0_dp\n\n end subroutine jacobn_testRB_dp\n\n subroutine deriv2_testRB_dp( x, y, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(dp) :: xtmp\n\n xtmp = x\n\n dydx(1) = (-0.013_dp-1000.0_dp*y(3))*y(1)\n dydx(2) = -2500.0_dp*y(3)*y(2)\n dydx(3) = -0.013_dp*y(1) + (-1000.0_dp*y(1)-2500.0_dp*y(2))*y(3)\n\n end subroutine deriv2_testRB_dp\n\n subroutine jacobn2_testRB_dp( x, y, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(dp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(dp) :: xtmp\n real(dp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_dp\n dfdx(2) = 0.0_dp\n dfdx(3) = 0.0_dp\n\n dfdy(1,1) = -0.013_dp-1000.0_dp*y(3)\n dfdy(1,2) = 0.0_dp\n dfdy(1,3) = -1000.0_dp*y(1)\n dfdy(2,1) = 0.0_dp\n dfdy(2,2) = -2500.0_dp*y(3)\n dfdy(2,3) = -2500.0_dp*y(2)\n dfdy(3,1) = -0.013_dp-1000.0_dp*y(3)\n dfdy(3,2) = -2500.0_dp*y(3)\n dfdy(3,3) = -1000.0_dp*y(1)-2500.0_dp*y(2)\n\n end subroutine jacobn2_testRB_dp\n\n subroutine deriv2_testRB_para_dp( x, y, para, dydx ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n\n real(dp), dimension(:), intent(in) :: para ! parameter\n\n real(dp) :: xtmp\n\n xtmp = x\n\n dydx(1) = (-0.013_dp-para(1)*y(3))*y(1)\n dydx(2) = -2500.0_dp*y(3)*y(2)\n dydx(3) = -0.013_dp*y(1) + (-1000.0_dp*y(1)-2500.0_dp*y(2))*y(3)\n\n end subroutine deriv2_testRB_para_dp\n\n subroutine jacobn2_testRB_para_dp( x, y, para, dfdx, dfdy ) ! returns derivatives dydx at x\n\n use mo_kind, only : dp\n\n implicit none\n\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(out) :: dfdx ! derivatives of f for x\n real(dp), dimension(:,:), intent(out) :: dfdy ! derivatives of f for y\n\n real(dp), dimension(:), intent(in) :: para ! parameter\n\n real(dp) :: xtmp\n real(dp), dimension(size(y,1)) :: ytmp\n\n xtmp = x\n ytmp = y\n\n dfdx(1) = 0.0_dp\n dfdx(2) = 0.0_dp\n dfdx(3) = 0.0_dp\n\n dfdy(1,1) = -0.013_dp-para(1)*y(3)\n dfdy(1,2) = 0.0_dp\n dfdy(1,3) = -1000.0_dp*y(1)\n dfdy(2,1) = 0.0_dp\n dfdy(2,2) = -2500.0_dp*y(3)\n dfdy(2,3) = -2500.0_dp*y(2)\n dfdy(3,1) = -0.013_dp-1000.0_dp*y(3)\n dfdy(3,2) = -2500.0_dp*y(3)\n dfdy(3,3) = -1000.0_dp*y(1)-2500.0_dp*y(2)\n\n end subroutine jacobn2_testRB_para_dp\n\nend module mo_eq_lv\n", "meta": {"hexsha": "7cdd6a9d62c8bf352498b544fbea47e71c876852", "size": 17654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_ode_solver/mo_eq_lv.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_ode_solver/mo_eq_lv.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_ode_solver/mo_eq_lv.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": 35.097415507, "max_line_length": 122, "alphanum_fraction": 0.4886144783, "num_tokens": 5040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.8723473763375644, "lm_q1q2_score": 0.8214495396448663}} {"text": "program newton\nuse funcs\nimplicit none\n\nreal(kind=8) :: Er, x_old, x_new\ninteger :: itermax, i\n\nx_old = -3.0 ! starting value of x\nitermax = 20\n\ni = 1\nEr = 1\nwrite(*,*) \"iteration x f(x) Err\"\ndo while (Er > 0.0001)\n ! determine the new x and the error:\n x_new = x_old - f(x_old)/df_dx(x_old)\n Er = dabs((x_new-x_old) / x_old)\n write(*,'(A2,I2,A2,3F12.7)') \" \", i, \" \", x_new, f(x_new), Er\n\n ! check if the maximum number of iterations has been exceeded:\n i = i+1 \n if (i > itermax) then\n write(*,*) \"The maximum number of iterations has been exceeded.\"\n exit\n end if\n\n x_old = x_new\nend do\n\nend program newton\n", "meta": {"hexsha": "ef41e1304d0e928691b45c0323300c515f60d517", "size": 654, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex1/a/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/HW4/ex1/a/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/HW4/ex1/a/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": 21.0967741935, "max_line_length": 70, "alphanum_fraction": 0.6100917431, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8214132502187902}} {"text": "module calculates\nimplicit none\ncontains\n\nreal(kind=8) function determinant(A)\n real(kind=8), dimension(3,3), intent(in) :: A\n\n determinant = 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))&\n + A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1))\nend function determinant\n\nsubroutine writes (A)\n real(kind=8), dimension(3,3), intent(in) :: A\n integer :: i, j\n\n do i = 1, 3\n write(*,'(20F8.3)') (A(i,j), j = 1, 3)\n end do\n write(*,*)\nend subroutine writes\n\nend module calculates\n", "meta": {"hexsha": "484e478aa223b009f48e2ce09003798510d7763b", "size": 514, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW2/ex4/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/ex4/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/ex4/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": 22.347826087, "max_line_length": 93, "alphanum_fraction": 0.5758754864, "num_tokens": 219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9732407206952993, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.8213130739804312}} {"text": "\tSUBROUTINE getgrid(Nx,Ny,Lx,Ly,pi,name_config,x,y,kx,ky)\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 2D nonlinear Klein-Gordon equation\n\t!\n\t! u_{tt}-u_{xx}+u_{yy}+u=Es*u^3\n\t!\n\t! The boundary conditions are u(x=0,y)=u(2*Lx*\\pi,y), \n\t!\tu(x,y=0)=u(x,y=2*Ly*\\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! Ny\t\t\t\t= number of modes in y - 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! Ly\t\t\t\t= width of box in y direction\n\t! OUTPUT\n\t!\n\t! .. Vectors ..\n\t! kx\t\t\t\t= fourier frequencies in x direction\n\t! ky\t\t\t\t= fourier frequencies in y direction\n\t! x\t\t\t\t= x locations\n\t! y\t\t\t\t= y 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! j\t\t\t\t= loop counter in y 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\tIMPLICIT NONE\t\t\t\t\t \n\tUSE omp_lib\t\t \t \n\t! Declare variables\n\tINTEGER(KIND=4), INTENT(IN)\t\t\t\t\t\t\t:: Nx,Ny\n\tREAL(kind=8), INTENT(IN)\t\t\t\t\t\t\t:: Lx,Ly,pi\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(OUT) \t\t\t:: x\n\tREAL(KIND=8), DIMENSION(1:NY), INTENT(OUT) \t\t\t:: y\n\tCOMPLEX(KIND=8), DIMENSION(1:NX), INTENT(OUT)\t\t:: kx\n\tCOMPLEX(KIND=8), DIMENSION(1:NY), INTENT(OUT)\t\t:: ky\n\tCHARACTER*100, INTENT(OUT)\t\t\t\t\t\t\t:: name_config\n\tINTEGER(kind=4)\t\t\t\t\t\t\t\t\t\t:: i,j\n\t\t\n\t!$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\n\tDO i=1,1+Nx/2\n\t\tkx(i)= cmplx(0.0d0,1.0d0)*REAL(i-1,kind(0d0))/Lx \t\t\t\n\tEND DO\n\t!$OMP END PARALLEL DO\n\tkx(1+Nx/2)=0.0d0\n\t!$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\n\tDO i = 1,Nx/2 -1\n\t\tkx(i+1+Nx/2)=-kx(1-i+Nx/2)\n\tEND DO\n\t!$OMP END PARALLEL DO\n\t\t\n\t!$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\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!$OMP END PARALLEL DO\n\t!$OMP PARALLEL DO PRIVATE(j) SCHEDULE(static)\n\tDO j=1,1+Ny/2\n\t\tky(j)= cmplx(0.0d0,1.0d0)*REAL(j-1,kind(0d0))/Ly \t\t\t\n\tEND DO\n\t!$OMP END PARALLEL DO\n\tky(1+Ny/2)=0.0d0\n\t!$OMP PARALLEL DO PRIVATE(j) SCHEDULE(static)\n\tDO j = 1,Ny/2 -1\n\t\tky(j+1+Ny/2)=-ky(1-j+Ny/2)\n\tEND DO\n\t!$OMP END PARALLEL DO\n\t!$OMP PARALLEL DO PRIVATE(j) SCHEDULE(static)\n\tDO j=1,Ny\n\t\ty(j)=(-1.0d0 + 2.0d0*REAL(j-1,kind(0d0))/REAL(Ny,kind(0d0)))*pi*Ly\n\tEND DO\n\t!$OMP END PARALLEL 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! Save y grid points in text format\n\tname_config = 'ycoord.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO j=1,Ny\n\t\tWRITE(11,*) y(j)\n\tEND DO\n\tCLOSE(11)\n\n\t\n\tEND SUBROUTINE getgrid", "meta": {"hexsha": "0fbae61c9d1027cb06abc5daa9aecca268877dba", "size": 3049, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "KleinGordon/Programs/KleinGordon2dThreadFFT/getgrid.f90", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "KleinGordon/Programs/KleinGordon2dThreadFFT/getgrid.f90", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "KleinGordon/Programs/KleinGordon2dThreadFFT/getgrid.f90", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 26.2844827586, "max_line_length": 70, "alphanum_fraction": 0.6031485733, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.8807970717197768, "lm_q1q2_score": 0.8213021456129522}} {"text": "PROGRAM quadratic\nIMPLICIT NONE\n REAL :: a, b, c ! The coefficients of a quadratic equation ax**2 + bx + c = 0\n REAL :: discriminant\n REAL :: rootA, rootB\n REAL :: real_part, imag_part\n WRITE(*, *) \"Enter the coefficients a, b, c of a quadratic equation.\"\n READ(*, *) a, b, c\n discriminant = b**2 - 4.0 * a * c\n\n WRITE(*, *) \"Coefficients: \", a, b, c\n WRITE(*, *) \"Discriminant: \", discriminant\n IF (discriminant < 0.0) THEN\n real_part = (-b) / (2.0 * a)\n imag_part = SQRT(ABS(discriminant)) / (2.0 * a)\n WRITE(*, *) \"The equation has complex roots.\"\n WRITE(*, *) \"x = \", real_part, \" + i\", imag_part\n WRITE(*, *) \"x = \", real_part, \" - i\", imag_part\n ELSE IF (discriminant > 0.0) THEN\n rootA = (-b + SQRT(discriminant)) / (2.0 * a)\n rootB = (-b - SQRT(discriminant)) / (2.0 * a)\n WRITE(*, *) \"The equation has two distinct real roots.\"\n WRITE(*, *) \"x = \", rootA\n WRITE(*, *) \"x = \", rootB\n ELSE\n rootA = (-b) / (2.0 * a)\n WRITE(*, *) \"The equation has two identical real roots.\"\n WRITE(*, *) \"x = \", rootA\n END IF\n\nEND PROGRAM quadratic\n", "meta": {"hexsha": "ade7f307f9c14728b0c66638912188f013b076ff", "size": 1091, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap3/quadratic.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/chap3/quadratic.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/chap3/quadratic.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": 34.09375, "max_line_length": 79, "alphanum_fraction": 0.5673693859, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8212082097662856}} {"text": "! Routine for n-dimensional optimization through\r\n! the golden section method.\r\n! Igor Lopes, February 2015 \r\nSUBROUTINE GOLDENSECTIONNDIM(XO,AO,AN,FN,NITER,SDIR,NDIM)\r\n IMPLICIT NONE\r\n ! Parameters\r\n REAL(8) R0 /0.0D0/\r\n REAL(8) R1 /1.0D0/\r\n REAL(8) R2 /2.0D0/\r\n REAL(8) R5 /5.0D0/\r\n ! Arguments\r\n INTEGER :: NITER,NDIM\r\n REAL(8),DIMENSION(NDIM) :: XO,SDIR\r\n REAL(8),DIMENSION(4) :: AN, FN\r\n REAL(8),DIMENSION(2) :: AO\r\n ! Locals\r\n INTEGER :: ITER\r\n REAL(8) :: TOL, TAU, EVALFUNC, GOLD\r\n REAL(8),DIMENSION(NDIM) :: XN\r\n ! Initialize\r\n FN=R0\r\n GOLD=(R1+DSQRT(R5))/R2\r\n TAU=R1/GOLD\r\n ! Begin algorithm\r\n AN(1)=AO(1)\r\n AN(4)=AO(2)\r\n XN=XO+AN(1)*SDIR\r\n FN(1)=EVALFUNC(XN,NDIM)\r\n XN=XO+AN(4)*SDIR\r\n FN(4)=EVALFUNC(XN,NDIM)\r\n AN(2)=AN(4)-TAU*(AN(4)-AN(1))\r\n AN(3)=AN(1)+TAU*(AN(4)-AN(1))\r\n XN=XO+AN(2)*SDIR\r\n FN(2)=EVALFUNC(XN,NDIM)\r\n XN=XO+AN(3)*SDIR\r\n FN(3)=EVALFUNC(XN,NDIM)\r\n DO ITER=1,NITER\r\n IF(FN(2).GT.FN(3))THEN\r\n AN(1)=AN(2)\r\n FN(1)=FN(2)\r\n AN(2)=AN(3)\r\n FN(2)=FN(3)\r\n AN(3)=AN(1)+TAU*(AN(4)-AN(1))\r\n XN=XO+AN(3)*SDIR\r\n FN(3)=EVALFUNC(XN,NDIM)\r\n ELSEIF(FN(2).LT.FN(3))THEN\r\n AN(4)=AN(3)\r\n FN(4)=FN(3)\r\n AN(3)=AN(2)\r\n FN(3)=FN(2)\r\n AN(2)=AN(4)-TAU*(AN(4)-AN(1))\r\n XN=XO+AN(2)*SDIR\r\n FN(2)=EVALFUNC(XN,NDIM)\r\n ELSE\r\n AN(1)=AN(2)\r\n FN(1)=FN(2)\r\n AN(4)=AN(3)\r\n FN(4)=FN(3)\r\n AN(2)=AN(4)-TAU*(AN(4)-AN(1))\r\n XN=XO+AN(2)*SDIR\r\n FN(2)=EVALFUNC(XN,NDIM)\r\n AN(3)=AN(1)+TAU*(AN(4)-AN(1))\r\n XN=XO+AN(3)*SDIR\r\n FN(3)=EVALFUNC(XN,NDIM)\r\n ENDIF\r\n ENDDO\r\nEND SUBROUTINE", "meta": {"hexsha": "eb089edc714b08017bafd2172c3d0c4fb0f490f8", "size": 1869, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/golden_section/goldensectionndim.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/golden_section/goldensectionndim.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/golden_section/goldensectionndim.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": 27.8955223881, "max_line_length": 58, "alphanum_fraction": 0.4622792937, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778073288128, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8211223724818209}} {"text": "| helper function to display size of function\n| Naive, recursive fib:\n: fib 00; dup 2 3 -- n ; returns fib of any number >3)\n >r seed fibo r> 0do fibo loop ;\n: fib2 ( n -- n ; returns fib of any number up to: 44)\n dup 0 =if drop 0 ;then\n dup 1 =if drop 1 ;then\n dup 2 =if drop 1 ;then\n fibon nip ;\n\n| That deals with the slow-down, but doesn't deal with the fact that both\n| routines fail after 44 fib, when it overflows the 32bit single-number\n| precision. We can rewrite it in double-number precision like so:\n\n| doublefib.rf\n\nneeds math/doubles\nwith~ ~doubles\n\n: drot ( a b c d e f -- c d e f a b )\n 4 pick >r 5 pick >r\n >r >r >r >r 2drop\n r> r> r> r> r> r> ;\n\n: d2dup ( a b cd -- a b c d a b c d )\n 2over 2over ;\n: dnip ( a b c d -- c d )\n\t2swap 2drop ;\n | swap 2 put nip ;\n: dseed -1L 1L ;\n: dfibo d2dup d+ drot 2drop ;\n: dfibon\n >r dseed dfibo r> 0do dfibo loop ;\n: fib3 ( n --; displays fib of any number up to: 90)\n dup 0if drop 0 . ;then\n dup 1 =if drop 1 . ;then\n dup 2 =if drop 1 . ;then\n dup 45 big 1 result int>big ;\n| non-recurse:\n: fibb2 ( n -- )\n\t1+\n\tseed2 0do\n\t\tsum result previous big+\n\t\tprevious result big-copy\n\t\tresult sum big-copy\n\tloop\n\tresult .big\n\t;\n\n2variable sum4\n2variable prev4\n: seed4 -1L prev4 2! ;\n: fib4 ( n -- )\n\tseed4\n\t1L rot\n\t1+ 0do\n\t\t2dup prev4 2@ d+ \n\t\tsum4 2dup 2! 2swap\n\t\tprev4 2!\n\tloop\n\td.\n\t;\n\ndefer thefib\n: fibs\n\tms@ temp !\n\t0do\n\t\t.\" Fibonacci number \" i . .\" is \" i thefib . cr\n\tloop\n\tms@ temp @ - cr . .\" msec\" cr\n\t;\n\n.\" fib (recursive, single): \" cr ' fib is thefib 30 fibs\n.\" fib2 (iterative, single): \" cr ' fib2 is thefib 30 fibs\n: fibs\n\tms@ temp !\n\t0do\n\t\t.\" Fibonacci number \" i . .\" is \" i thefib cr\n\tloop\n\tms@ temp @ - cr . .\" msec\" cr\n\t;\n: tryfibs 50 fibs ;\n.\" fib3 (iterative, double): \" cr ' fib3 is thefib tryfibs\n\n: dobig\n\t.\" fib4 (iterative, double): \" cr ['] fib4 is thefib tryfibs\n\t.\" fibb2 (iterative, bigmath) : \" cr ['] fibb2 is thefib tryfibs\n\t;\n~bigmath.imath [IF]\n\tdobig\n[ELSE]\n.\" imath library not loaded\" cr\n[THEN]\nbye\n", "meta": {"hexsha": "4510f7f49ffc9935f91ae0bff74578e223dc1264", "size": 2588, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/fib2.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/fib2.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/fib2.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": 21.5666666667, "max_line_length": 79, "alphanum_fraction": 0.6136012365, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746095, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.8207498502950237}} {"text": "PROGRAM stats_1\r\n!\r\n! Purpose:\r\n! To calculate mean and the standard deviation of an input\r\n! data set containing an arbitrary number of input values.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/10/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nINTEGER :: n = 0 ! The number of input samples.\r\nREAL :: std_dev = 0. ! The standard deviation of the input samples.\r\nREAL :: sum_x = 0. ! The sum of the input values. \r\nREAL :: sum_x2 = 0. ! The sum of the squares of the input values. \r\nREAL :: x = 0. ! An input data value.\r\nREAL :: x_bar ! The average of the input samples.\r\n\r\n! While Loop to read input values.\r\nDO\r\n ! Read in next value\r\n WRITE (*,*) 'Enter number: '\r\n READ (*,*) x \r\n WRITE (*,*) 'The number is ', x \r\n\r\n ! Test for loop exit\r\n IF ( x < 0 ) EXIT\r\n \r\n ! Otherwise, accumulate sums.\r\n n = n + 1\r\n sum_x = sum_x + x\r\n sum_x2 = sum_x2 + x**2\r\nEND DO\r\n\r\n! Calculate the mean and standard deviation\r\nx_bar = sum_x / real(n)\r\nstd_dev = SQRT( (real(n) * sum_x2 - sum_x**2) / (real(n) * real(n-1)) )\r\n\r\n! Tell user.\r\nWRITE (*,*) 'The mean of this data set is:', x_bar\r\nWRITE (*,*) 'The standard deviation is: ', std_dev\r\nWRITE (*,*) 'The number of data points is:', n\r\n\r\nEND PROGRAM stats_1\r\n", "meta": {"hexsha": "b35511af2fe11be2fd2b75c6bd9ee44b08de6001", "size": 1454, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap4/stats_1.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/chap4/stats_1.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/chap4/stats_1.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.2916666667, "max_line_length": 72, "alphanum_fraction": 0.5777166437, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9773708039218115, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.820731463064269}} {"text": "C$Procedure VPROJ ( Vector projection, 3 dimensions )\n \n SUBROUTINE VPROJ ( A, B, P )\n \nC$ Abstract\nC\nC VPROJ finds the projection of one vector onto another vector.\nC 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 to be projected.\nC B I The vector onto which A is to be projected.\nC P O The projection of A onto B.\nC\nC$ Detailed_Input\nC\nC A is a double precision, 3-dimensional vector. This\nC vector is to be projected onto the vector B.\nC\nC B is a double precision, 3-dimensional vector. This\nC vector is the vector which receives the projection.\nC\nC$ Detailed_Output\nC\nC P is a double precision, 3-dimensional vector containing the\nC projection of A onto B. (P is necessarily parallel to B.)\nC If B is the zero vector then P will be returned as the zero\nC vector.\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 given any vectors A and B there is a unique decomposition of\nC A as a sum V + P such that V the dot product of V and B is zero,\nC and the dot product of P with B is equal the product of the\nC lengths of P and B. P is called the projection of A onto B. It\nC can be expressed mathematically as\nC\nC DOT(A,B)\nC -------- * B\nC DOT(B,B)\nC\nC (This is not necessarily the prescription used to compute the\nC projection. It is intended only for descriptive purposes.)\nC\nC$ Examples\nC\nC The following table gives sample inputs and results from calling\nC VPROJ.\nC\nC A B NDIM P\nC -------------------------------------------------------\nC (6, 6, 6) ( 2, 0, 0) 3 (6, 0, 0)\nC (6, 6, 6) (-3, 0, 0) 3 (6, 0, 0)\nC (6, 6, 0) ( 0, 7, 0) 3 (0, 6, 0)\nC (6, 0, 0) ( 0, 0, 9) 3 (0, 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 W.L. Taber (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 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC 3-dimensional vector projection\nC\nC-&\n \n DOUBLE PRECISION VDOT\nC\n DOUBLE PRECISION BIGA\n DOUBLE PRECISION BIGB\n DOUBLE PRECISION R(3)\n DOUBLE PRECISION T(3)\n DOUBLE PRECISION SCALE\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 \n IF ( BIGA .EQ. 0 ) THEN\n P(1) = 0.0D0\n P(2) = 0.0D0\n P(3) = 0.0D0\n RETURN\n END IF\n \n IF ( BIGB .EQ. 0 ) THEN\n P(1) = 0.0D0\n P(2) = 0.0D0\n P(3) = 0.0D0\n RETURN\n END IF\n \n R(1) = B(1) / BIGB\n R(2) = B(2) / BIGB\n R(3) = B(3) / BIGB\n \n T(1) = A(1) / BIGA\n T(2) = A(2) / BIGA\n T(3) = A(3) / BIGA\n \n SCALE = VDOT (T,R) * BIGA / VDOT (R,R)\n \n CALL VSCL ( SCALE, R, P )\n \n RETURN\n END\n", "meta": {"hexsha": "d2f9b42e8006a50f04e0bcbb05ce97339300d9a3", "size": 5131, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vproj.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/vproj.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/vproj.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.8858695652, "max_line_length": 71, "alphanum_fraction": 0.5920873124, "num_tokens": 1615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182321, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8206954511694732}} {"text": "module Gauss\n\n\n contains\n\n function gauss_points_weights(ngps) result(vect_gauss)\n\n !! Gauss points and weights\n ! Give the exact integral for 2n-1 degree of polinomials.\n ! n: Number of gauss's points.\n implicit none\n integer :: ngps\n double precision :: term1, term2, term3, term4\n !integer, dimension(:) :: sizeg\n double precision, dimension(ngps,2) :: vect_gauss\n\n !sizeg = (/ ngps, ngps /)\n\n if (ngps==1) then\n\n vect_gauss(1,:) = (/0.D0 , 2.D0 /) ![[0],[2]];\n\n else if (ngps==2) then\n\n vect_gauss(:,1) = (/ -sqrt(1/3.D0) , sqrt(1/3.D0) /) ! [[-sqrt(1/3);sqrt(1/3)],[1;1]];\n vect_gauss(:,2) = (/ 1.D0, 1.D0 /)\n\n else if (ngps==3) then\n\n vect_gauss(:,1) = (/ -sqrt(3/5.D0), 0.D0, sqrt(3/5.D0) /)\n vect_gauss(:,2) = (/ 5/9.D0, 8/9.D0, 5/9.D0 /)\n\n !vect_gauss=[[-sqrt(3/5);0;sqrt(3/5)],[5/9;8/9;5/9]];\n else !(ngps==4)\n\n term1 = -sqrt((3+2*sqrt(6/5.D0))/7)\n term2 = -sqrt((3-2*sqrt(6/5.D0))/7)\n term3 = sqrt((3-2*sqrt(6/5.D0))/7)\n term4 = sqrt((3+2*sqrt(6/5.D0))/7)\n\n vect_gauss(:,1) = (/ term1 , term2 , term3 , term4 /)\n vect_gauss(:,2) = (/ (18-sqrt(30.D0))/36 , (18+sqrt(30.D0))/36 , (18+sqrt(30.D0))/36 , (18-sqrt(30.D0))/36 /)\n\n!(18-sqrt(30))/36; (18-sqrt(30))/36 ; (18+sqrt(30))/36 ; (18+sqrt(30))/36\n! [2,4,3,1]\n! gaussn4 =[[sqrt((3+2*sqrt(6/5))/7);-sqrt((3+2*sqrt(6/5))/7);sqrt((3-2*sqrt(6/5))/7);-sqrt((3-2*sqrt(6/5))/7)],[(18-sqrt(30))/36;(18-sqrt(30))/36;(18+sqrt(30))/36;(18+sqrt(30))/36]];\n ![ord,I1]=sort(gaussn4(:,1));\n !I.gauss_s=gaussn4(I1,:);\n\n end if\n\n\n end function gauss_points_weights\n\n\nend module Gauss\n", "meta": {"hexsha": "4d89afc94ba7e17410844e45fc8df38cac3d68e9", "size": 1683, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "ROMlab_Fortran/bin/LATIN/Gauss.f03", "max_stars_repo_name": "SebastianRodriguezIturra/Fortran_LATIN_PGD", "max_stars_repo_head_hexsha": "dbaa9610ede47d72267c8e9cd59b9f6a1dfba033", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:02:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T21:02:53.000Z", "max_issues_repo_path": "ROMlab_Fortran/bin/LATIN/Gauss.f03", "max_issues_repo_name": "SebastianRodriguezIturra/Fortran_LATIN_PGD", "max_issues_repo_head_hexsha": "dbaa9610ede47d72267c8e9cd59b9f6a1dfba033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-05T20:30:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-05T20:30:10.000Z", "max_forks_repo_path": "ROMlab_Fortran/bin/LATIN/Gauss.f03", "max_forks_repo_name": "SebastianRodriguezIturra/Fortran_LATIN_PGD", "max_forks_repo_head_hexsha": "dbaa9610ede47d72267c8e9cd59b9f6a1dfba033", "max_forks_repo_licenses": ["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.5263157895, "max_line_length": 190, "alphanum_fraction": 0.5294117647, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741241296944, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8206790069462929}} {"text": "module gcd_module\n implicit none\n\n contains\n recursive integer function gcd(a, b) result(answer)\n implicit none\n\n integer, intent(in) :: a, b\n\n if (b==0) then\n answer = a\n else\n answer = gcd(b,mod(a,b))\n end if\n end function\nend module\n\nprogram ch1209\n ! Recursive Version of gcd\n use gcd_module\n implicit none\n\n integer :: i, j, result\n\n print *, 'type in two integers'\n read *, i, j\n result = gcd(i,j)\n print *, 'gcd is ', result\nend program\n", "meta": {"hexsha": "f2b7d0a67dbd3563420f07b1fe81ef91fedd172d", "size": 537, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch12/ch1209.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/ch1209.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/ch1209.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": 17.9, "max_line_length": 55, "alphanum_fraction": 0.5661080074, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109812297141, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8205768655502979}} {"text": "PROGRAM SimpsonsRuleForIntegration\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 SimpsonsRule(a, b, Area, N)\n WRITE(*, *) \"Area under the curve is: \", Area\n\n CONTAINS\n SUBROUTINE SimpsonsRule(a, b, Area, N)\n IMPLICIT NONE \n REAL:: a, b, Area, h\n INTEGER:: N, i\n REAL, DIMENSION(N-1):: X\n ! N is number of segment\n IF(N .LT. 2) THEN\n Area = 0.0\n RETURN \n ENDIF\n h = (b-a)/N\n DO i = 1, N-1\n X(i) = a + i * h\n ENDDO\n Area = f(a) + f(b)\n DO i = 1, N/2\n Area = Area + 4 * f(X(2*i-1))\n ENDDO\n DO i = 1, (N+1)/2 - 1\n Area = Area + 2 * f(X(2*i))\n ENDDO\n Area = (h/3) * Area\n END SUBROUTINE SimpsonsRule\n\n REAL FUNCTION f(x)\n IMPLICIT NONE \n REAL:: x \n f = EXP(x)\n return\n END FUNCTION f\n\nEND PROGRAM SimpsonsRuleForIntegration\n", "meta": {"hexsha": "944d146be4917b289478e179d94d394d741d8666", "size": 1152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Integration/Simpsons_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/Simpsons_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/Simpsons_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": 25.0434782609, "max_line_length": 74, "alphanum_fraction": 0.4722222222, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517061554854, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.8205689222156823}} {"text": "module stats_mod\r\nuse kind_mod, only: dp\r\nimplicit none\r\npublic :: mode, mean, median\r\ninterface median\r\n module procedure median_real, median_int\r\nend interface median\r\ninteger, parameter :: bad_int = -999\r\ncontains\r\npure function mean(x) result(y)\r\nreal(kind=dp), intent(in) :: x(:)\r\nreal(kind=dp) :: y\r\ny = sum(x)/max(1,size(x))\r\nend function mean\r\n!\r\npure function mode(ivec) result(imode)\r\ninteger, intent(in) :: ivec(:)\r\ninteger :: imode\r\ninteger :: i,freq_max,freq,imin\r\nif (size(ivec) < 1) then\r\n imode = bad_int\r\n return\r\nend if\r\nimin = minval(ivec)\r\nimode = imin\r\nfreq_max = count(ivec == imode)\r\ndo i=minval(ivec)+1,maxval(ivec)\r\n freq = count(ivec == i)\r\n if (freq > freq_max) then\r\n freq_max = freq\r\n imode = i\r\n end if\r\nend do\r\nend function mode\r\n!\r\nfunction median_real(xx) result(xmed)\r\n! return the median of xx(:)\r\nreal(kind=dp), intent(in) :: xx(:)\r\nreal(kind=dp) :: xmed\r\nreal(kind=dp) :: xcopy(size(xx))\r\nxcopy = xx\r\ncall median_sub(xcopy,size(xx),xmed)\r\nend function median_real\r\n!\r\nfunction median_int(xx) result(xmed)\r\n! return the median of xx(:)\r\ninteger, intent(in) :: xx(:)\r\nreal(kind=dp) :: xmed\r\nxmed = median_real(real(xx,kind=dp))\r\nend function median_int\r\n!\r\nsubroutine median_sub(x,n,xmed)\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! N.B. On exit, the array X is partially ordered.\r\n! By Alan Miller\r\n! Latest revision - 26 November 1996\r\nimplicit none\r\ninteger, intent(in) :: n\r\nreal(kind=dp), intent(in out) :: x(:)\r\nreal(kind=dp), intent(out) :: xmed\r\n! Local variables\r\nreal(kind=dp) :: temp, xhi, xlo, xmax, xmin\r\nlogical :: odd\r\ninteger :: hi, lo, nby2, nby2p1, mid, i, j, k\r\nnby2 = n / 2\r\nnby2p1 = nby2 + 1\r\nodd = .true.\r\n! HI & LO are position limits encompassing the median.\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.0_dp\r\n return\r\n end if\r\n xmed = x(1)\r\n if (n == 1) return\r\n xmed = 0.5_dp*(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.5_dp*(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.5_dp*(xmin + xmax)\r\nend subroutine median_sub\r\nend module stats_mod", "meta": {"hexsha": "996d0985ac05d2819fa221081f7d52e09db35ee7", "size": 3806, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "stats.f90", "max_stars_repo_name": "Beliavsky/RetirementSpending", "max_stars_repo_head_hexsha": "8cab2de632c0ce0e1f9024a8e1fa17d9124cb3b7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-18T02:38:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T11:25:23.000Z", "max_issues_repo_path": "stats.f90", "max_issues_repo_name": "Beliavsky/RetirementSpending", "max_issues_repo_head_hexsha": "8cab2de632c0ce0e1f9024a8e1fa17d9124cb3b7", "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": "stats.f90", "max_forks_repo_name": "Beliavsky/RetirementSpending", "max_forks_repo_head_hexsha": "8cab2de632c0ce0e1f9024a8e1fa17d9124cb3b7", "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": 22.3882352941, "max_line_length": 74, "alphanum_fraction": 0.5851287441, "num_tokens": 1354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8887587905460027, "lm_q1q2_score": 0.8203591712933929}} {"text": "module chebval\nimplicit none\n\ncontains\n\nreal recursive function chebpoly(x_val, degree) result(polval)\n real, intent(in) :: x_val\n integer, intent(in) :: degree\n\n if (degree == 0) then\n polval = 1\n else if (degree == 1) then\n polval = x_val\n else\n polval = 2 * x_val * chebpoly(x_val, degree-1) - chebpoly(x_val, degree-2)\n endif\nend function chebpoly\n\nreal function chebserie(coeffs, tdim, x_val) result(serie)\n implicit none\n integer, intent(in) :: tdim\n real, intent(in) :: x_val\n real, dimension(tdim), intent(in) :: coeffs\n integer :: i\n\n do i = 1, tdim\n serie = serie + coeffs(i) * chebpoly(x_val, tdim)\n enddo \n \nend function chebserie\n \nend module chebval", "meta": {"hexsha": "6ad83fde74df9a638a33ffdd222314f0d9f8036a", "size": 735, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chebval.f90", "max_stars_repo_name": "Panadestein/nmode_prod_cheb", "max_stars_repo_head_hexsha": "772eb6347109d4594726234bc0452cbe1556573b", "max_stars_repo_licenses": ["MIT"], "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/chebval.f90", "max_issues_repo_name": "Panadestein/nmode_prod_cheb", "max_issues_repo_head_hexsha": "772eb6347109d4594726234bc0452cbe1556573b", "max_issues_repo_licenses": ["MIT"], "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/chebval.f90", "max_forks_repo_name": "Panadestein/nmode_prod_cheb", "max_forks_repo_head_hexsha": "772eb6347109d4594726234bc0452cbe1556573b", "max_forks_repo_licenses": ["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.96875, "max_line_length": 82, "alphanum_fraction": 0.6367346939, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102589923635, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.8203327124663232}} {"text": "subroutine gcd_bin(value, u, v)\n integer, intent(out) :: value\n integer, intent(inout) :: u, v\n integer :: k, t\n\n u = abs(u)\n v = abs(v)\n if( u < v ) then\n t = u\n u = v\n v = t\n endif\n if( v == 0 ) then\n value = u\n return\n endif\n k = 1\n do while( (mod(u, 2) == 0).and.(mod(v, 2) == 0) )\n u = u / 2\n v = v / 2\n k = k * 2\n enddo\n if( (mod(u, 2) == 0) ) then\n t = u\n else\n t = -v\n endif\n do while( t /= 0 )\n do while( (mod(t, 2) == 0) )\n t = t / 2\n enddo\n if( t > 0 ) then\n u = t\n else\n v = -t\n endif\n t = u - v\n enddo\n value = u * k\nend subroutine gcd_bin\n", "meta": {"hexsha": "c5657150cfe396b5bda2456ccc3de1c49d798b47", "size": 656, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Greatest-common-divisor/Fortran/greatest-common-divisor-4.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-4.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-4.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.0, "max_line_length": 51, "alphanum_fraction": 0.4222560976, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.8199862376155155}} {"text": "!--------------------------------------------------------------------\n!\n!\n! PURPOSE\n!\n! This program numerically solves the 2D incompressible Navier-Stokes\n! on a Square Domain [0,1]x[0,1] using pseudo-spectral methods and\n! Crank-Nicolson timestepping. The numerical solution is compared to\n! the exact Taylor-Green Vortex Solution. \n!\n! Periodic free-slip boundary conditions and Initial conditions:\n! u(x,y,0)=sin(2*pi*x)cos(2*pi*y)\n! v(x,y,0)=-cos(2*pi*x)sin(2*pi*y)\n! Analytical Solution:\n! u(x,y,t)=sin(2*pi*x)cos(2*pi*y)exp(-8*pi^2*nu*t)\n! v(x,y,t)=-cos(2*pi*x)sin(2*pi*y)exp(-8*pi^2*nu*t)\n!\n! .. Parameters ..\n! Nx = number of modes in x - power of 2 for FFT\n! Ny = number of modes in y - power of 2 for FFT\n! Nt = number of timesteps to take\n! Tmax = maximum simulation time\n! FFTW_IN_PLACE = value for FFTW input \n! FFTW_MEASURE = value for FFTW input\n! FFTW_EXHAUSTIVE = value for FFTW input\n! FFTW_PATIENT = value for FFTW input \n! FFTW_ESTIMATE = value for FFTW input\n! FFTW_FORWARD = value for FFTW input\n! FFTW_BACKWARD = value for FFTW input \n! pi = 3.14159265358979323846264338327950288419716939937510d0\n! mu = viscosity\n! rho = density\n! .. Scalars ..\n! i = loop counter in x direction\n! j = loop counter in y direction\n! n = loop counter for timesteps direction \n! allocatestatus = error indicator during allocation\n! count = keep track of information written to disk\n! iol = size of array to write to disk\n! start = variable to record start time of program\n! finish = variable to record end time of program\n! count_rate = variable for clock count rate\n! planfx = Forward 1d fft plan in x\n! planbx = Backward 1d fft plan in x\n! planfy = Forward 1d fft plan in y\n! planby = Backward 1d fft plan in y\n! dt = timestep\n! .. Arrays ..\n! u = velocity in x direction\n! uold = velocity in x direction at previous timestep\n! v = velocity in y direction\n! vold = velocity in y direction at previous timestep\n! u_y = y derivative of velocity in x direction\n! v_x = x derivative of velocity in y direction\n! omeg = vorticity in real space\n! omegold = vorticity in real space at previous\n! iterate\n! omegcheck = store of vorticity at previous iterate\n! omegoldhat = 2D Fourier transform of vorticity at previous\n! iterate\n! omegoldhat_x = x-derivative of vorticity in Fourier space\n! at previous iterate\n! omegold_x = x-derivative of vorticity in real space \n! at previous iterate\n! omegoldhat_y = y-derivative of vorticity in Fourier space \n! at previous iterate\n! omegold_y = y-derivative of vorticity in real space\n! at previous iterate\n! nlold = nonlinear term in real space\n! at previous iterate\n! nloldhat = nonlinear term in Fourier space\n! at previous iterate\n! omeghat = 2D Fourier transform of vorticity\n! at next iterate\n! omeghat_x = x-derivative of vorticity in Fourier space\n! at next timestep\n! omeghat_y = y-derivative of vorticity in Fourier space\n! at next timestep\n! omeg_x = x-derivative of vorticity in real space\n! at next timestep\n! omeg_y = y-derivative of vorticity in real space\n! at next timestep\n! .. Vectors ..\n! kx = fourier frequencies in x direction\n! ky = fourier frequencies in y direction\n! kxx = square of fourier frequencies in x direction\n! kyy = square of fourier frequencies in y direction\n! x = x locations\n! y = y locations\n! time = times at which save data\n! name_config = array to store filename for data to be saved \n! fftfx = array to setup x Fourier transform\n! fftbx = array to setup y Fourier transform\n! REFERENCES\n!\n! ACKNOWLEDGEMENTS\n!\n! ACCURACY\n! \n! ERROR INDICATORS AND WARNINGS\n!\n! FURTHER COMMENTS\n! This program has not been optimized to use the least amount of memory\n! but is intended as an example only for which all states can be saved\n!--------------------------------------------------------------------\n! External routines required\n! \n! External libraries required\n! FFTW3 -- Fast Fourier Transform in the West Library\n! (http://www.fftw.org/) \n! declare variables\nPROGRAM main\n use nsadaptor_glue\n IMPLICIT NONE \n INTEGER(kind=4), PARAMETER :: Nx=256 \n INTEGER(kind=4), PARAMETER :: Ny=256 \n REAL(kind=8), PARAMETER :: dt=0.00125 \n REAL(kind=8), PARAMETER &\n :: pi=3.14159265358979323846264338327950288419716939937510\n REAL(kind=8), PARAMETER :: rho=1.0d0 \n REAL(kind=8), PARAMETER :: mu=1.0d0 \n REAL(kind=8), PARAMETER :: tol=0.1d0**10 \n REAL(kind=8) :: chg \n INTEGER(kind=4), PARAMETER :: nplots=50\n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: time\n COMPLEX(kind=8), DIMENSION(:), ALLOCATABLE :: kx,kxx \n COMPLEX(kind=8), DIMENSION(:), ALLOCATABLE :: ky,kyy \n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: x \n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: y \n COMPLEX(kind=8), DIMENSION(:,:), ALLOCATABLE :: & \n u,uold,v,vold,u_y,v_x,omegold, omegcheck, omeg,&\n omegoldhat, omegoldhat_x, omegold_x,& \n omegoldhat_y, omegold_y, nlold, nloldhat,&\n omeghat, omeghat_x, omeghat_y, omeg_x, omeg_y,&\n nl, nlhat, psihat, psihat_x, psi_x, psihat_y, psi_y\n\n ! added for coprocessing\n real(kind=8), dimension(:,:), allocatable :: dump\n\n REAL(kind=8),DIMENSION(:,:), ALLOCATABLE :: uexact_y,vexact_x,omegexact\n INTEGER(kind=4) :: i,j,k,n, allocatestatus, count, iol\n INTEGER(kind=4) :: start, finish, count_rate\n INTEGER(kind=4), PARAMETER :: FFTW_IN_PLACE = 8, FFTW_MEASURE = 0, &\n FFTW_EXHAUSTIVE = 8, FFTW_PATIENT = 32, &\n FFTW_ESTIMATE = 64\n INTEGER(kind=4),PARAMETER :: FFTW_FORWARD = -1, FFTW_BACKWARD=1 \n COMPLEX(kind=8), DIMENSION(:,:), ALLOCATABLE :: fftfx,fftbx\n INTEGER(kind=8) :: planfxy,planbxy\n CHARACTER*100 :: name_config\n \n CALL system_clock(start,count_rate) \n ALLOCATE(time(1:nplots),kx(1:Nx),kxx(1:Nx),ky(1:Ny),kyy(1:Ny),x(1:Nx),y(1:Ny),&\n u(1:Nx,1:Ny),uold(1:Nx,1:Ny),v(1:Nx,1:Ny),vold(1:Nx,1:Ny),u_y(1:Nx,1:Ny),&\n v_x(1:Nx,1:Ny),omegold(1:Nx,1:Ny),omegcheck(1:Nx,1:Ny), omeg(1:Nx,1:Ny),&\n omegoldhat(1:Nx,1:Ny),omegoldhat_x(1:Nx,1:Ny), omegold_x(1:Nx,1:Ny), &\n omegoldhat_y(1:Nx,1:Ny),omegold_y(1:Nx,1:Ny), nlold(1:Nx,1:Ny), nloldhat(1:Nx,1:Ny),&\n omeghat(1:Nx,1:Ny), omeghat_x(1:Nx,1:Ny), omeghat_y(1:Nx,1:Ny), omeg_x(1:Nx,1:Ny),&\n omeg_y(1:Nx,1:Ny), nl(1:Nx,1:Ny), nlhat(1:Nx,1:Ny), psihat(1:Nx,1:Ny), &\n psihat_x(1:Nx,1:Ny), psi_x(1:Nx,1:Ny), psihat_y(1:Nx,1:Ny), psi_y(1:Nx,1:Ny),&\n uexact_y(1:Nx,1:Ny), vexact_x(1:Nx,1:Ny), omegexact(1:Nx,1:Ny),fftfx(1:Nx,1:Ny),&\n fftbx(1:Nx,1:Ny),dump(1:Nx,1:Ny),stat=AllocateStatus) \n IF (AllocateStatus .ne. 0) STOP \n PRINT *,'allocated space'\n \n ! set up ffts\n CALL dfftw_plan_dft_2d_(planfxy,Nx,Ny,fftfx(1:Nx,1:Ny),fftbx(1:Nx,1:Ny),&\n FFTW_FORWARD,FFTW_EXHAUSTIVE)\n CALL dfftw_plan_dft_2d_(planbxy,Nx,Ny,fftbx(1:Nx,1:Ny),fftfx(1:Nx,1:Ny),&\n FFTW_BACKWARD,FFTW_EXHAUSTIVE)\n \n ! setup fourier frequencies in x-direction\n DO i=1,1+Nx/2\n kx(i)= 2.0d0*pi*cmplx(0.0d0,1.0d0)*REAL(i-1,kind(0d0)) \n END DO\n kx(1+Nx/2)=0.0d0\n DO i = 1,Nx/2 -1\n kx(i+1+Nx/2)=-kx(1-i+Nx/2)\n END DO\n DO i=1,Nx\n kxx(i)=kx(i)*kx(i)\n END DO\n DO i=1,Nx\n x(i)=REAL(i-1,kind(0d0))/REAL(Nx,kind(0d0)) \n END DO\n \n ! setup fourier frequencies in y-direction\n DO j=1,1+Ny/2\n ky(j)= 2.0d0*pi*cmplx(0.0d0,1.0d0)*REAL(j-1,kind(0d0)) \n END DO\n ky(1+Ny/2)=0.0d0\n DO j = 1,Ny/2 -1\n ky(j+1+Ny/2)=-ky(1-j+Ny/2)\n END DO\n DO j=1,Ny\n kyy(j)=ky(j)*ky(j)\n END DO\n DO j=1,Ny\n y(j)=REAL(j-1,kind(0d0))/REAL(Ny,kind(0d0)) \n END DO\n PRINT *,'Setup grid and fourier frequencies'\n \n \n DO j=1,Ny\n DO i=1,Nx\n u(i,j)=sin(2.0d0*pi*x(i))*cos(2.0d0*pi*y(j))\n v(i,j)=-cos(2.0d0*pi*x(i))*sin(2.0d0*pi*y(j))\n u_y(i,j)=-2.0d0*pi*sin(2.0d0*pi*x(i))*sin(2.0d0*pi*y(j))\n v_x(i,j)=2.0d0*pi*sin(2.0d0*pi*x(i))*sin(2.0d0*pi*y(j))\n omeg(i,j)=v_x(i,j)-u_y(i,j)\n END DO\n END DO\n \n ! Vorticity to Fourier Space\n CALL dfftw_execute_dft_(planfxy,omeg(1:Nx,1:Ny),omeghat(1:Nx,1:Ny)) \n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!Initial nonlinear term !!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n ! obtain \\hat{\\omega}_x^{n,k}\n DO j=1,Ny\n omeghat_x(1:Nx,j)=omeghat(1:Nx,j)*kx(1:Nx)\n END DO\n ! obtain \\hat{\\omega}_y^{n,k}\n DO i=1,Nx\n omeghat_y(i,1:Ny)=omeghat(i,1:Ny)*ky(1:Ny)\n END DO\n ! convert to real space \n CALL dfftw_execute_dft_(planbxy,omeghat_x(1:Nx,1:Ny),omeg_x(1:Nx,1:Ny))\n CALL dfftw_execute_dft_(planbxy,omeghat_y(1:Nx,1:Ny),omeg_y(1:Nx,1:Ny))\n ! compute nonlinear term in real space\n DO j=1,Ny\n nl(1:Nx,j)=u(1:Nx,j)*omeg_x(1:Nx,j)/REAL(Nx*Ny,kind(0d0))+&\n v(1:Nx,j)*omeg_y(1:Nx,j)/REAL(Nx*Ny,kind(0d0)) \n END DO\n CALL dfftw_execute_dft_(planfxy,nl(1:Nx,1:Ny),nlhat(1:Nx,1:Ny)) \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n time(1)=0.0d0\n PRINT *,'Got initial data, starting timestepping'\n call coprocessorinitializewithpython(\"pipeline.py\", 11)\n \n DO n=1,nplots\n chg=1\n ! save old values\n uold(1:Nx,1:Ny)=u(1:Nx,1:Ny)\n vold(1:Nx,1:Ny)=v(1:Nx,1:Ny)\n omegold(1:Nx,1:Ny)=omeg(1:Nx,1:Ny)\n omegcheck(1:Nx,1:Ny)=omeg(1:Nx,1:Ny) \n omegoldhat(1:Nx,1:Ny)=omeghat(1:Nx,1:Ny)\n nloldhat(1:Nx,1:Ny)=nlhat(1:Nx,1:Ny)\n DO WHILE (chg>tol) \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!nonlinear fixed (n,k+1)!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n ! obtain \\hat{\\omega}_x^{n+1,k}\n DO j=1,Ny\n omeghat_x(1:Nx,j)=omeghat(1:Nx,j)*kx(1:Nx) \n END DO\n ! obtain \\hat{\\omega}_y^{n+1,k}\n DO i=1,Nx\n omeghat_y(i,1:Ny)=omeghat(i,1:Ny)*ky(1:Ny)\n END DO\n ! convert back to real space \n CALL dfftw_execute_dft_(planbxy,omeghat_x(1:Nx,1:Ny),omeg_x(1:Nx,1:Ny)) \n CALL dfftw_execute_dft_(planbxy,omeghat_y(1:Nx,1:Ny),omeg_y(1:Nx,1:Ny))\n ! calculate nonlinear term in real space\n DO j=1,Ny\n nl(1:Nx,j)=u(1:Nx,j)*omeg_x(1:Nx,j)/REAL(Nx*Ny,kind(0d0))+&\n v(1:Nx,j)*omeg_y(1:Nx,j)/REAL(Nx*Ny,kind(0d0))\n END DO\n ! convert back to fourier\n CALL dfftw_execute_dft_(planfxy,nl(1:Nx,1:Ny),nlhat(1:Nx,1:Ny)) \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n ! obtain \\hat{\\omega}^{n+1,k+1} with Crank Nicolson timestepping\n DO j=1,Ny\n omeghat(1:Nx,j)=( (1.0d0/dt+0.5d0*(mu/rho)*(kxx(1:Nx)+kyy(j)))&\n *omegoldhat(1:Nx,j) - 0.5d0*(nloldhat(1:Nx,j)+nlhat(1:Nx,j)))/&\n (1.0d0/dt-0.5d0*(mu/rho)*(kxx(1:Nx)+kyy(j))) \n END DO\n \n ! calculate \\hat{\\psi}^{n+1,k+1}\n DO j=1,Ny\n psihat(1:Nx,j)=-omeghat(1:Nx,j)/(kxx(1:Nx)+kyy(j))\n END DO\n psihat(1,1)=0.0d0\n psihat(Nx/2+1,Ny/2+1)=0.0d0\n psihat(Nx/2+1,1)=0.0d0\n psihat(1,Ny/2+1)=0.0d0\n \n ! obtain \\psi_x^{n+1,k+1} and \\psi_y^{n+1,k+1}\n DO j=1,Ny\n psihat_x(1:Nx,j)=psihat(1:Nx,j)*kx(1:Nx)\n END DO\n CALL dfftw_execute_dft_(planbxy,psihat_x(1:Nx,1:Ny),psi_x(1:Nx,1:Ny)) \n DO i=1,Nx\n psihat_y(i,1:Ny)=psihat(i,1:Ny)*ky(1:Ny)\n END DO\n CALL dfftw_execute_dft_(planbxy,psihat_y(1:Ny,1:Ny),psi_y(1:Ny,1:Ny)) \n DO j=1,Ny\n psi_x(1:Nx,j)=psi_x(1:Nx,j)/REAL(Nx*Ny,kind(0d0))\n psi_y(1:Nx,j)=psi_y(1:Nx,j)/REAL(Nx*Ny,kind(0d0))\n END DO \n \n ! obtain \\omega^{n+1,k+1}\n CALL dfftw_execute_dft_(planbxy,omeghat(1:Nx,1:Ny),omeg(1:Nx,1:Ny)) \n DO j=1,Ny\n omeg(1:Nx,j)=omeg(1:Nx,j)/REAL(Nx*Ny,kind(0d0))\n END DO\n \n ! obtain u^{n+1,k+1} and v^{n+1,k+1} using stream function (\\psi) in real space\n DO j=1,Ny\n u(1:Nx,j)=psi_y(1:Nx,j)\n v(1:Nx,j)=-psi_x(1:Nx,j)\n END DO \n \n ! check for convergence \n chg=maxval(abs(omeg-omegcheck)) \n ! saves {n+1,k+1} to {n,k} for next iteration\n omegcheck=omeg \n END DO\n time(n+1)=time(n)+dt\n PRINT *,'TIME ',time(n+1)\n ! call adaptor here\n ! not sure if there's a way to cleanly pass complex to C++ code\n do j = 1, Ny\n do i = 1, Nx\n dump(i,j) = real(omeg(i,j), kind(0d0))\n end do\n end do\n call nsadaptor(Nx, Ny, 1, n, time(n), dump)\n END DO\n \n call coprocessorfinalize()\n\n DO j=1,Ny\n DO i=1,Nx\n uexact_y(i,j)=-2.0d0*pi*sin(2.0d0*pi*x(i))*sin(2.0d0*pi*y(j))*&\n exp(-8.0d0*mu*(pi**2)*nplots*dt)\n vexact_x(i,j)=2.0d0*pi*sin(2.0d0*pi*x(i))*sin(2.0d0*pi*y(j))*&\n exp(-8.0d0*mu*(pi**2)*nplots*dt)\n omegexact(i,j)=vexact_x(i,j)-uexact_y(i,j)\n END DO\n END DO\n \n name_config = 'omegafinal.datbin' \n INQUIRE(iolength=iol) omegexact(1,1)\n OPEN(unit=11,FILE=name_config,form=\"unformatted\", access=\"direct\",recl=iol) \n count = 1 \n DO j=1,Ny\n DO i=1,Nx\n WRITE(11,rec=count) REAL(omeg(i,j),KIND(0d0))\n count=count+1\n END DO\n END DO\n CLOSE(11)\n \n name_config = 'omegaexactfinal.datbin' \n OPEN(unit=11,FILE=name_config,form=\"unformatted\", access=\"direct\",recl=iol) \n count = 1 \n DO j=1,Ny\n DO i=1,Nx\n WRITE(11,rec=count) omegexact(i,j)\n count=count+1\n END DO\n END DO\n CLOSE(11)\n\n name_config = 'xcoord.dat' \n OPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \n REWIND(11)\n DO i=1,Nx\n WRITE(11,*) x(i)\n END DO\n CLOSE(11)\n\n name_config = 'ycoord.dat' \n OPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \n REWIND(11)\n DO j=1,Ny\n WRITE(11,*) y(j)\n END DO\n CLOSE(11)\n \n CALL dfftw_destroy_plan_(planfxy)\n CALL dfftw_destroy_plan_(planbxy)\n CALL dfftw_cleanup_()\n \n DEALLOCATE(time,kx,kxx,ky,kyy,x,y,&\n u,uold,v,vold,u_y,v_x,omegold, omegcheck, omeg, &\n omegoldhat, omegoldhat_x, omegold_x,& \n omegoldhat_y, omegold_y, nlold, nloldhat,&\n omeghat, omeghat_x, omeghat_y, omeg_x, omeg_y,&\n nl, nlhat, psihat, psihat_x, psi_x, psihat_y, psi_y,&\n uexact_y,vexact_x,omegexact, &\n fftfx,fftbx,stat=AllocateStatus) \n IF (AllocateStatus .ne. 0) STOP \n PRINT *,'Program execution complete'\nEND PROGRAM main\n", "meta": {"hexsha": "6c1a04da7ba14380c539a99fd1daf7c613c10bbe", "size": 15518, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NavierStokes/Programs/NewParaViewAPI/navierstokes.f90", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "NavierStokes/Programs/NewParaViewAPI/navierstokes.f90", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "NavierStokes/Programs/NewParaViewAPI/navierstokes.f90", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 38.5062034739, "max_line_length": 93, "alphanum_fraction": 0.5516174765, "num_tokens": 5612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.8199365532592746}} {"text": "! Daniel R. Reynolds\n! SMU Mathematics\n! Math 4370/6370\n! 7 February 2015\n!=================================================================\n\n\nsubroutine initialize(u,v1,v2,v3,c,dx,dy,nx,ny)\n !===============================================================\n ! Description: \n ! Sets the initial conditions into u, v1, v2, v3.\n !===============================================================\n ! inclusions\n implicit none\n\n ! declarations\n integer, intent(in) :: nx, ny\n real*8, intent(in) :: c, dx, dy\n real*8, dimension(nx,ny), intent(out) :: u, v1, v2, v3\n real*8 :: xspan_c(nx), xspan_h(nx), yspan_c(ny), yspan_h(ny)\n real*8 :: x_c, x_h, y_c, y_h\n integer :: i, j\n \n ! internals\n \n ! set mesh points\n do i=1,nx\n xspan_c(i) = dx/2.d0 + (i-1)*dx\n xspan_h(i) = (i-1)*dx\n end do\n\n do j=1,ny\n yspan_c(j) = dy/2.d0 + (j-1)*dy\n yspan_h(j) = (j-1)*dy\n end do\n\n\n ! set initial condition for solution and derivatives\n do j=1,ny\n\n ! y locations\n y_c = yspan_c(j)\n y_h = yspan_h(j)\n\n do i=1,nx\n\n ! x locations\n x_c = xspan_c(i)\n x_h = xspan_h(i)\n\n ! set initial conditions on u_x, u_y [gaussian blob]\n ! u(0,x,y) = exp(-100*((x-1/3)^2+(y-1/2)^2))\n ! c*u_x(0,x,y) = -200*c*(x-1/3)*exp(-100*((x-1/3)^2+(y-1/2)^2))\n ! c*u_y(0,x,y) = -200*c*(y-1/2)*exp(-100*((x-1/3)^2+(y-1/2)^2))\n u(i,j) = exp(-1.d2*((x_c-1.d0/3.d0)**2+(y_c-0.5d0)**2))\n v1(i,j) = 0.d0\n v2(i,j) = -2.d2*c*(x_h-1.d0/3.d0)*exp(-1.d2*((x_h-1.d0/3.d0)**2+(y_c-0.5d0)**2))\n v3(i,j) = -2.d2*c*(y_h-0.5d0)*exp(-1.d2*((x_c-1.d0/3.d0)**2+(y_h-0.5d0)**2))\n\n end do\n end do\n \n return\n\n ! end program\nend subroutine initialize\n!=================================================================\n", "meta": {"hexsha": "059b3921599fa307832e93e856359f1d60ff0968", "size": 1791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "advection/initialize.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": "advection/initialize.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": "advection/initialize.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": 26.3382352941, "max_line_length": 88, "alphanum_fraction": 0.4505862647, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8199309292916193}} {"text": "*\n* pythag - Calaculates the hypotenuse given two sides of a triangle\n*\n* Written by: C. Severance 16Mar92\n*\n* Declare the variables:\n*\n REAL A,B,HYP\n*\n* Prompt the user two sides of the triangle\n*\n PRINT *,'Enter the first side of the triangle - '\n READ *,A\n PRINT *,'Enter the second side of the triangle - '\n READ *,B\n*\n* Calculate the hypotenuse\n*\n HYP = SQRT ( A ** 2 + B ** 2 )\n PRINT *,'Third side of the triangle is - ',HYP\n END\n", "meta": {"hexsha": "721b6a23229a3a80f11c3a94d403a5e2f7ff475d", "size": 478, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/pythag.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/pythag.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/pythag.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": 21.7272727273, "max_line_length": 67, "alphanum_fraction": 0.6087866109, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8198255867514365}} {"text": "\n PROGRAM TEST\n USE FMZM\n IMPLICIT NONE\n\n! Least squares fit for the coefficients in the asymptotic series for the Jth harmonic number.\n\n! H(J) = 1 + 1/2 + 1/3 + ... + 1/J defines the Jth harmonic number.\n\n! Find an approximation to H(J) of the form:\n\n! ln(J) + c(1) + c(2)/J + ... + c(k)/J**(k-1)\n\n! Integrating 1/x from 1 to J gives ln(J) as a first approximation, and we generate N data\n! points (x(i),y(i)) where x(i) is J and y(i) is H(J) for various J values. Then we do a\n! least squares fit of the model function c(1) + c(2)/J + ... + c(k)/J**(k-1) to the data\n! (x(i),y(i)-ln(i)).\n\n! Since this is a sample problem, we can compare the results of the fit to the \"true\"\n! asymptotic formula, where c(1) = 0.57721566..., Euler's constant, and for i > 1,\n! c(i) = -B(i-1)/(i-1). The B values are Bernoulli numbers, and the first few are:\n! B(1) = -1/2, B(2) = 1/6, B(4) = -1/30, B(6) = 1/42, ..., with the others being zero:\n! B(3) = B(5) = B(7) = ... = 0.\n\n! The first c's in the list of fitted coefficients give the most agreement with the\n! theoretical values, and the last ones the least. The linear system is ill-conditioned,\n! but by using high precision we can get good accuracy for several coefficients.\n! For example, using 400 digit precision, 60 data points at intervals of 100 (i.e.,\n! x(i) = 100, 200, 300, ..., 6000), and fitting 60 coefficients, we get at least 50\n! decimal agreement between the fitted c's and the theoretical ones for c(1), ..., c(29).\n! c(41) agrees to 16 decimals, and because the number is large this is 31 significant\n! digit agreement.\n\n INTEGER :: J, K, N, NGAP\n TYPE (FM) :: H_N, ONE, DET\n TYPE (FM), ALLOCATABLE :: A(:,:), B(:), C(:), X(:), Y(:)\n TYPE (FM), EXTERNAL :: F\n\n! This is not a good way to compute Euler's constant, but with 150 digit precision,\n! N = 40 data points at intervals of NGAP = 10, fitting K = 40 coefficients we get\n! c(1) = .57721566490153286060651209008240243104215933593992,\n! correct to 50 places.\n\n! Set FM precision.\n\n CALL FM_SET(150)\n\n! N is the number of harmonic data points.\n\n N = 40\n\n! NGAP is the gap between harmonic data points.\n\n NGAP = 10\n\n! K is the number of coefficients to fit.\n\n K = 40\n\n ALLOCATE(A(K,K),B(K),C(K),X(N),Y(N),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in HFIT. Unable to allocate arrays with K,N = ',2I8/)\") K,N\n STOP\n ENDIF\n\n! Generate the harmonic data points.\n! Since the coefficient of the first term in the model, ln(x), is assumed\n! to be 1 and is not being fitted, subtract that from the Y data points.\n\n H_N = 0\n ONE = 1\n WRITE (*,*) ' '\n WRITE (*,*) ' Data points:'\n WRITE (*,*) ' '\n DO J = 1, N*NGAP\n H_N = H_N + ONE/J\n IF (MOD(J,NGAP) == 0) THEN\n X(J/NGAP) = J\n Y(J/NGAP) = H_N - LOG(X(J/NGAP))\n WRITE (*,\"(A,I4,A,I6,A,A)\") ' I = ',J/NGAP,' X = ',J,' Y = ', &\n TRIM(FM_FORMAT('F40.35',Y(J/NGAP)))\n ENDIF\n ENDDO\n\n! Generate the linear system for the normal equations.\n\n CALL FM_GENEQ(F,A,B,K,X,Y,N)\n\n! Solve the linear system for the normal equations.\n\n CALL FM_LIN_SOLVE(A,C,B,N,DET)\n\n! Print the solution.\n! When using F format, FM doesn't like to print 0.00000...0 showing no\n! significant digits when the actual number is too small for that format.\n! FM will shift to E format when possible, to avoid showing all zeroes.\n! In this example, all the even-numbered coefficients are zero in the\n! asymptotic series for the harmonic numbers, so any non-zero digits\n! found in the fit are not interesting. Therefore the if statement\n! below prints exactly zero when C(J) is too small, making the output\n! look neater.\n\n WRITE (*,*) ' '\n WRITE (*,*) ' Fitted coefficients:'\n DO J = 1, K\n IF (ABS(C(J)) > 1.0D-50) THEN\n WRITE (*,\"(A,I3,A,A)\") ' J = ',J,' C(J) = ',TRIM(FM_FORMAT('F60.50',C(J)))\n ELSE\n WRITE (*,\"(A,I3,A,A)\") ' J = ',J,' C(J) = ',TRIM(FM_FORMAT('F60.50',TO_FM(0)))\n ENDIF\n ENDDO\n\n END PROGRAM TEST\n\n FUNCTION F(J,X) RESULT (RETURN_VALUE)\n USE FMZM\n IMPLICIT NONE\n\n! This defines the model function being fitted to the data points.\n! For the harmonic number case, the model function is:\n\n! F(J,X) = 1/X**(J-1)\n\n! This will fit the terms c1 + c2/n + c3/n**2 + ... to the harmonic model function\n! ln(x) + c1 + c2/n + c3/n**2 + ....\n\n INTEGER :: J\n TYPE (FM) :: RETURN_VALUE, X\n\n RETURN_VALUE = 1/X**(J-1)\n\n END FUNCTION F\n", "meta": {"hexsha": "30ef99b1b40c23ce878c72472315724cffd6450e", "size": 4899, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/HarmonicFitFM.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/HarmonicFitFM.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/HarmonicFitFM.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.8345864662, "max_line_length": 95, "alphanum_fraction": 0.566442131, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810481379379, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.8196969064570835}} {"text": "submodule(forlab) forlab_det\n use forlab_kinds\n\ncontains\n module procedure det_sp\n real(sp), dimension(:, :), allocatable :: L, U\n integer :: m\n\n if (issquare(A)) then\n m = size(A, 1)\n if (m .eq. 2) then\n det_sp = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n elseif (m .eq. 3) then\n det_sp = A(1, 1)*A(2, 2)*A(3, 3) &\n + A(2, 1)*A(3, 2)*A(1, 3) &\n + A(3, 1)*A(1, 2)*A(2, 3) &\n - A(1, 1)*A(3, 2)*A(2, 3) &\n - A(3, 1)*A(2, 2)*A(1, 3) &\n - A(2, 1)*A(1, 2)*A(3, 3)\n else\n call lu(A, L, U)\n det_sp = product(diag(U))\n if (present(outL)) outL = L\n if (present(outU)) outU = U\n end if\n else\n stop \"Error: in det(A), A should be square.\"\n end if\n return\n end procedure\n module procedure det_dp\n real(dp), dimension(:, :), allocatable :: L, U\n integer :: m\n\n if (issquare(A)) then\n m = size(A, 1)\n if (m .eq. 2) then\n det_dp = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n elseif (m .eq. 3) then\n det_dp = A(1, 1)*A(2, 2)*A(3, 3) &\n + A(2, 1)*A(3, 2)*A(1, 3) &\n + A(3, 1)*A(1, 2)*A(2, 3) &\n - A(1, 1)*A(3, 2)*A(2, 3) &\n - A(3, 1)*A(2, 2)*A(1, 3) &\n - A(2, 1)*A(1, 2)*A(3, 3)\n else\n call lu(A, L, U)\n det_dp = product(diag(U))\n if (present(outL)) outL = L\n if (present(outU)) outU = U\n end if\n else\n stop \"Error: in det(A), A should be square.\"\n end if\n return\n end procedure\n module procedure det_qp\n real(qp), dimension(:, :), allocatable :: L, U\n integer :: m\n\n if (issquare(A)) then\n m = size(A, 1)\n if (m .eq. 2) then\n det_qp = A(1, 1)*A(2, 2) - A(1, 2)*A(2, 1)\n elseif (m .eq. 3) then\n det_qp = A(1, 1)*A(2, 2)*A(3, 3) &\n + A(2, 1)*A(3, 2)*A(1, 3) &\n + A(3, 1)*A(1, 2)*A(2, 3) &\n - A(1, 1)*A(3, 2)*A(2, 3) &\n - A(3, 1)*A(2, 2)*A(1, 3) &\n - A(2, 1)*A(1, 2)*A(3, 3)\n else\n call lu(A, L, U)\n det_qp = product(diag(U))\n if (present(outL)) outL = L\n if (present(outU)) outU = U\n end if\n else\n stop \"Error: in det(A), A should be square.\"\n end if\n return\n end procedure\nend submodule\n", "meta": {"hexsha": "4c3a680b3ed8447a4aa2841856dceb84116fa798", "size": 3191, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_det.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_det.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_det.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": 37.9880952381, "max_line_length": 62, "alphanum_fraction": 0.3102475713, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.8196969018792384}} {"text": " subroutine wlog(xr,xi,yr,yi)\n*\n* PURPOSE\n* wlog compute the logarithm of a complex number\n* y = yr + i yi = log(x), x = xr + i xi \n*\n* CALLING LIST / PARAMETERS\n* subroutine wlog(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* METHOD \n* adapted with some modifications from Hull, \n* Fairgrieve, Tang, \"Implementing Complex \n* Elementary Functions Using Exception Handling\", \n* ACM TOMS, Vol. 20 (1994), pp 215-244\n*\n* y = yr + i yi = log(x)\n* yr = log(|x|) = various formulae depending where x is ...\n* yi = Arg(x) = atan2(xi, xr)\n* \n implicit none\n\n* PARAMETER\n double precision xr, xi, yr, yi\n\n* LOCAL VAR\n double precision a, b, t, r\n* CONSTANTS\n\n double precision R2\n\n parameter (R2 = 1.41421356237309504d0)\n\n* EXTERNAL\n\n double precision dlamch, logp1, pythag\n external dlamch, logp1, pythag\n\n* STATIC VAR\n logical first\n double precision RMAX, LSUP, LINF\n\n save first\n data first /.true./\n save RMAX, LSUP, LINF\n\n if (first) then\n RMAX = dlamch('O')\n LINF = sqrt(dlamch('U'))\n LSUP = sqrt(0.5d0*RMAX)\n first = .false.\n endif\n\n* (0) avoid memory pb ...\n a = xr\n b = xi\n\n* (1) compute the imaginary part\n yi = atan2(b, a)\n\n* (2) compute the real part\n a = abs(a)\n b = abs(b)\n\n* Order a and b such that 0 <= b <= a\n if (b .gt. a) then\n t = b\n b = a\n a = t\n endif\n\n if ( (0.5d0 .le. a) .and. (a .le. R2) ) then\n yr = 0.5d0*logp1((a-1.d0)*(a+1.d0) + b*b)\n elseif (LINF .lt. b .and. a .lt. LSUP) then\n* no overflow or underflow can occur in computing a*a + b*b \n yr = 0.5d0*log(a*a + b*b)\n elseif (a .gt. RMAX) then\n* overflow\n yr = a\n else\n t = pythag(a,b)\n if (t .le. RMAX) then\n yr = log(t)\n else\n* handle rare spurious overflow with :\n r = b/a\n yr = log(a) + 0.5d0*logp1(r*r)\n endif\n endif\n\n end\n\n", "meta": {"hexsha": "7b89e66a83171b8f10ee459e95a538bc02a523fb", "size": 2357, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/wlog.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/wlog.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/wlog.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.2989690722, "max_line_length": 67, "alphanum_fraction": 0.5070004243, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075766298657, "lm_q2_score": 0.8519528057272544, "lm_q1q2_score": 0.8196702493212635}} {"text": "! Module for defining statistical functions\n\nmodule stats_funcs\n implicit none\n contains\n\n real*8 function mean1(x,n)\n\n implicit none\n integer, intent(in) :: n\n real*8, dimension(n), intent(in) :: x\n \n mean1 = sum(x)/real(n)\n \n end function mean1\n\n real*8 function vars1(x,n)\n\n implicit none\n integer, intent(in) :: n\n real*8, dimension(n), intent(in) :: x\n integer :: i\n \n vars1 = mean1([(x(i)**2, i=1,n)],n) - (mean1(x,n))**2\n\n end function vars1\n \n real*8 function stdev1(x,n)\n \n implicit none\n integer, intent(in) :: n\n real*8, intent(in), dimension(n) :: x\n \n stdev1 = (vars1(x,n))**0.5\n \n end function stdev1\n \n real*8 function cov_var12(x,y,n)\n \n implicit none\n integer, intent(in) :: n\n real*8, dimension(n), intent(in) :: x, y\n integer :: i\n \n cov_var12 = mean1([(x(i)*y(i), i=1,n)],n) - mean1(x,n)* &\n & mean1(y,n)\n \n end function cov_var12\n \n real*8 function corr_12(x,y,n)\n \n implicit none\n integer, intent(in) :: n\n real*8, intent(in), dimension(n) :: x, y\n \n corr_12 = cov_var12(x,y,n)/(stdev1(x,n)*stdev1(y,n))\n \n end function corr_12\n \n subroutine print_mat1(b,n)\n\n implicit none\n integer, intent(in) :: n\n real*8, dimension(n), intent(in) :: b\n integer :: i\n \n do i=1,n\n write(*,'(\"|\",f8.3,\" |\")',advance='yes'),b(i)\n end do\n\n end subroutine\n \nend module stats_funcs\n", "meta": {"hexsha": "b1d4a43ce6124bb1100ba9e7e5a7542c27c40252", "size": 1626, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Statistical_Functions/m_statistics.f95", "max_stars_repo_name": "aandrich3/fortran", "max_stars_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Statistical_Functions/m_statistics.f95", "max_issues_repo_name": "aandrich3/fortran", "max_issues_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-11T20:42:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-11T20:42:37.000Z", "max_forks_repo_path": "Statistical_Functions/m_statistics.f95", "max_forks_repo_name": "aandrich3/fortran", "max_forks_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-11T17:22:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-06T14:41:36.000Z", "avg_line_length": 21.972972973, "max_line_length": 65, "alphanum_fraction": 0.5030750308, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065794, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.8196056374343238}} {"text": "program main\n !=======================================================================================\n implicit none\n\n !=== Local data\n integer :: n\n\n !=== External procedures\n double precision, external :: catalan_numbers\n\n !=== Execution =========================================================================\n\n write(*,'(1x,a)')'==============='\n write(*,'(5x,a,6x,a)')'n','c(n)'\n write(*,'(1x,a)')'---------------'\n\n do n = 0, 14\n write(*,'(1x,i5,i10)') n, int(catalan_numbers(n))\n enddo\n\n write(*,'(1x,a)')'==============='\n\n !=======================================================================================\nend program main\n!BL\n!BL\n!BL\ndouble precision recursive function catalan_numbers(n) result(value)\n !=======================================================================================\n implicit none\n\n !=== Input, ouput data\n integer, intent(in) :: n\n\n !=== Execution =========================================================================\n\n if ( n .eq. 0 ) then\n value = 1\n else\n value = ( 2.0d0 * dfloat(2 * n - 1) / dfloat( n + 1 ) ) * catalan_numbers(n-1)\n endif\n\n !=======================================================================================\nend function catalan_numbers\n", "meta": {"hexsha": "55f2da808bce4ca0e697a720311c450efa58a64f", "size": 1279, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Catalan-numbers/Fortran/catalan-numbers.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/Catalan-numbers/Fortran/catalan-numbers.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/Catalan-numbers/Fortran/catalan-numbers.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": 28.4222222222, "max_line_length": 90, "alphanum_fraction": 0.3205629398, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.8194960076132957}} {"text": "! ============================ Module Description ===========================\n! PHI_MOD: Initilizes Phi functions for scaler arguments. Contains:\n! 1. phi - initilizes phi functions using contour integral & recursion\n! relation.\n! ===========================================================================\n\nmodule phi_mod\n\n ! Module Parameters\n use tools_mod, only: dp, norm, PI, II\n implicit none\n\n ! Cauchy Integral Settings\n real(dp), parameter :: c_tol = 1.0_dp ! Smallest Lambda for contour integral\n real(dp), parameter :: c_R = 2.0_dp*c_tol ! Contour Radius\n integer, parameter :: c_M = 32 ! Number of Points\n\n contains\n\n ! =======================================================================\n ! PHI Evaluates \\phi_i(L) for i=0,...,n and scaler/vector L using\n ! Recursion relation and Cauchy Integral Formula.\n !\n ! Arguments\n !\n ! L (input) COMPLEX*16 array, dimensions(n)\n ! array of Lambda values cooresponding to PDE linear component\n !\n ! n (input) INTEGER\n ! highest phi function to initialize.\n !\n ! P (output) COMPLEX*16, dimensions(n,size(L))\n ! array where on exit P(i,j) = \\phi_{i-1}(L(j))\n ! =======================================================================\n\n subroutine phi(L,n,P)\n ! Arguments\n complex(dp), intent(in) :: L(:)\n integer, intent(in) :: n\n complex(dp), intent(out) :: P(n+1,size(L))\n ! Local Variables\n integer :: i,j,k,nL\n real(dp) :: f\n complex(dp) :: z(c_M)\n complex(dp) :: Li,Lzi,pp\n\n nL = size(L)\n P = 0;\n ! Set contour points\n do i=1,c_M\n z(i) = c_R * exp(2.0_dp*PI*II*(i-1.0_dp)/real(c_M,dp))\n enddo\n ! Compute Phi\n do i=1,nL\n Li = L(i)\n if(abs(Li) >= c_tol) then\n ! Direct Formula\n P(1,i) = exp(Li)\n f = 1.0_dp;\n do j=2,n+1\n P(j,i) = (P(j-1,i) - 1.0_dp/f)/Li\n f = f*(j-1)\n enddo\n else\n ! Cauchy Integral Formula\n do k=1,c_M\n Lzi = Li + z(k)\n pp = exp(Lzi)\n P(1,i) = P(1,i) + pp/c_M\n f = 1.0_dp;\n do j=2,n+1\n pp = (pp - 1.0_dp/f)/Lzi\n P(j,i) = P(j,i) + pp/c_M;\n f = f*(j-1)\n enddo\n enddo\n ! remove imaginary roundoff if L(i) is real\n if(aimag(Li) == 0.0_dp) then\n P(:,i) = REALPART(P(:,i))\n endif\n end if\n end do\nend subroutine phi\n\nend module phi_mod", "meta": {"hexsha": "6020b5695720f079aae9abbd4248fef0d7fc4071", "size": 2849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/phi_mod.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/phi_mod.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/phi_mod.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": 33.5176470588, "max_line_length": 90, "alphanum_fraction": 0.4113724114, "num_tokens": 739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750387190131, "lm_q2_score": 0.8596637523076224, "lm_q1q2_score": 0.8194959967663809}} {"text": "MODULE ROOT\n IMPLICIT NONE \n\n INTEGER, PARAMETER :: IMAX = 30\n INTEGER, PARAMETER :: NGRID = 100\n REAL, PARAMETER :: TOLERANCE = 1.0E-5\n REAL, PARAMETER :: PI = 3.141592653589793\n\nCONTAINS\n\n FUNCTION BRACKET(f, a, b, debug)\n IMPLICIT NONE\n\n REAL :: f\n REAL, INTENT(IN) :: a, b\n INTEGER, INTENT(IN) :: debug\n INTEGER :: BRACKET\n\n REAL :: h\n REAL, DIMENSION(NGRID) :: grid, fgrid\n INTEGER :: i\n\n OPTIONAL :: debug\n\n ! initialization \n BRACKET = 0 \n h = (b - a) / (NGRID - 1)\n grid(:) = [ (a + h * i, i = 0, NGRID - 1) ]\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) &\n PRINT 1000, 'n', 'x', 'f(x)'\n\n ! value of f at each grid point \n DO i = 1, NGRID\n fgrid(i) = f(grid(i))\n ! debug message \n IF ( PRESENT(debug) .AND. debug == 1 ) &\n PRINT 2000, i, grid(i), fgrid(i) \n END DO\n\n ! count the number of times f changes sign, \n ! i.e. number of root \n DO i = 1, NGRID - 1\n IF ( fgrid(i) * fgrid(i+1) < 0 ) BRACKET = BRACKET + 1\n END DO\n\n 1000 FORMAT (A3, 2(A10, 3X))\n 2000 FORMAT (I3, 2(F13.6))\n END FUNCTION BRACKET\n\n FUNCTION BISECTION(f, a, b, debug)\n IMPLICIT NONE\n\n REAL :: f\n REAL, INTENT(IN) :: a, b\n INTEGER, INTENT(IN) :: debug\n REAL :: BISECTION\n\n REAL :: a_n, b_n, x_n_1, x_n, error\n INTEGER :: nstep = 0\n\n OPTIONAL debug \n\n ! assumption: [a, b]\n IF ( a > b ) THEN\n PRINT '(A)', \"WRONG BRACKET ORDER\"\n RETURN \n ! intermeidate value theorem \n ELSE IF ( f(a) * f(b) > 0 ) THEN\n PRINT '(A)', \"ROOT IS NOT BRACKETED\"\n RETURN\n END IF\n\n ! initialization \n a_n = a\n b_n = b \n x_n_1 = a_n\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 1000, 'n', 'a', 'b', 'x', 'f(x)', 'error'\n\n DO\n nstep = nstep + 1\n\n ! next guess \n x_n = 0.5 * ( a_n + b_n )\n\n ! relative error \n error = ABS((x_n - x_n_1) / x_n)\n\n ! debug \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 2000, nstep, a_n, b_n, x_n, f(x_n), error \n\n ! termination\n x_n_1 = x_n\n IF ( error < TOLERANCE ) THEN \n BISECTION = x_n\n RETURN \n END IF\n\n ! reset the bracket \n IF ( f(x_n) * f(a_n) < 0.0 ) THEN\n b_n = x_n\n ELSE\n a_n = x_n\n END IF\n END DO\n\n 1000 FORMAT (A3, 3(A10, 3X), A13, 4X, A13)\n 2000 FORMAT (I3, 3F13.6, 2(4X, ES13.6))\n END FUNCTION BISECTION\n\n FUNCTION FALSE_POSITION(f, a, b, debug)\n IMPLICIT NONE\n\n REAL :: f\n REAL, INTENT(IN) :: a, b\n INTEGER, INTENT(IN) :: debug\n REAL :: FALSE_POSITION\n\n REAL :: a_n, b_n, x_n_1, x_n, error\n INTEGER :: nstep = 0\n\n OPTIONAL debug \n\n ! assumption: [a, b]\n IF ( a > b ) THEN\n PRINT '(A)', \"WRONG BRACKET ORDER\"\n RETURN \n ! intermeidate value theorem \n ELSE IF ( f(a) * f(b) > 0 ) THEN\n PRINT '(A)', \"ROOT IS NOT BRACKETED\"\n RETURN\n END IF\n\n ! initializationn\n a_n = a \n b_n = b\n x_n_1 = a_n\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 1000, 'n', 'a', 'b', 'x', 'f(x)', 'error'\n\n DO\n nstep = nstep + 1\n\n ! next guess \n x_n = (a_n * f(b_n) - b_n * f(a_n)) / (f(b_n) - f(a_n))\n\n ! relative error \n error = ABS((x_n - x_n_1) / x_n)\n\n ! debug \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 2000, nstep, a_n, b_n, x_n, f(x_n), error \n\n ! termination\n x_n_1 = x_n\n IF ( error < TOLERANCE ) THEN \n FALSE_POSITION = x_n\n RETURN \n END IF \n\n ! reset the bracket \n IF ( f(x_n) * f(a_n) < 0.0 ) THEN\n b_n = x_n\n ELSE\n a_n = x_n\n END IF\n END DO\n\n 1000 FORMAT (A3, 3(A10, 3X), A13, 4X, A13)\n 2000 FORMAT (I3, 3F13.6, 2(4X, ES13.6))\n END FUNCTION FALSE_POSITION\n\n FUNCTION NEWTON_RAPHSON(f, df, x_0, debug)\n IMPLICIT NONE\n\n REAL :: f, df\n REAL, INTENT(IN) :: x_0\n INTEGER, INTENT(IN) :: debug \n REAL :: NEWTON_RAPHSON\n\n REAL :: x_n_1, x_n, error\n INTEGER :: nstep = 0\n\n OPTIONAL debug \n\n ! initializationn\n x_n_1 = x_0\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 1000, 'n', 'x', 'f(x)', 'error'\n\n ! iteration \n DO\n nstep = nstep + 1\n\n ! next guess \n x_n = x_n_1 - f(x_n_1) / df(x_n_1) \n\n ! relative error \n error = ABS((x_n - x_n_1) / x_n_1)\n\n ! debug \n IF ( PRESENT(debug) ) & \n PRINT 2000, nstep, x_n, f(x_n), error\n\n ! termination\n x_n_1 = x_n \n IF ( error < TOLERANCE ) THEN \n NEWTON_RAPHSON = x_n\n RETURN\n ENDIF\n END DO\n\n 1000 FORMAT (A3, (A10, 3X), A13, 4X, A13)\n 2000 FORMAT (I3, F13.6, 2(4X, ES13.6))\n END FUNCTION NEWTON_RAPHSON\n\n FUNCTION SECANT(f, x_0, x_1, debug)\n IMPLICIT NONE\n\n REAL :: f\n REAL, INTENT(IN) :: x_0, x_1\n INTEGER, INTENT(IN) :: debug \n REAL :: SECANT\n\n REAL :: x_n_2, x_n_1, x_n, error \n INTEGER :: nstep = 0 \n\n OPTIONAL debug \n\n !initialization\n x_n_2 = x_0\n x_n_1 = x_1\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 1000, 'n', 'x', 'f(x)', 'error'\n\n DO\n nstep = nstep + 1\n\n ! next guess \n x_n = x_n - f(x_n_1) * (x_n_1 - x_n_2) / (f(x_n_1) - f(x_n_2))\n\n ! relative error \n error = ABS((x_n - x_n_1) / x_n_1)\n\n ! debug \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 2000, nstep, x_n, f(x_n), error \n\n ! termination\n x_n_2 = x_n_1\n x_n_1 = x_n \n IF ( error < TOLERANCE ) THEN \n SECANT = x_n\n RETURN \n END IF \n END DO\n\n 1000 FORMAT (A3, (A10, 3X), A13, 4X, A13)\n 2000 FORMAT (I3, F13.6, 2(4X, ES13.6))\n END FUNCTION SECANT \n\n FUNCTION MUELLER(f, x_0, x_1, x_2, debug)\n IMPLICIT NONE\n\n REAL :: f\n REAL, INTENT(IN) :: x_0, x_1, x_2\n INTEGER, INTENT(IN) :: debug\n REAL :: MUELLER\n\n REAL :: x_n_3, x_n_2, x_n_1, x_n, error\n REAL :: a, b, c, delta\n INTEGER :: nstep = 0\n\n OPTIONAL debug \n\n ! initialiazation\n x_n_3 = x_0\n x_n_2 = x_1\n x_n_1 = x_2\n\n ! debug header \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 1000, 'n', 'x', 'f(x)', 'error'\n\n DO\n nstep = nstep + 1\n\n a = ((f(x_n_3) - f(x_n_1)) * (x_n_2 - x_n_1) - (f(x_n_2) - f(x_n_1)) * (x_n_3 - x_n_1)) / &\n ((x_n_3 - x_n_1) * (x_n_2 - x_n_1) * (x_n_3 - x_n_2))\n b = ((f(x_n_2) - f(x_n_1)) * (x_n_3 - x_n_1)**2 - (f(x_n_3) - f(x_n_1)) * (x_n_2 - x_n_1)**2) / &\n ((x_n_3 - x_n_1) * (x_n_2 - x_n_1) * (x_n_3 - x_n_2))\n c = f(x_n_1)\n\n ! special Delta \n delta = b**2 - 4*a*c\n\n ! next guess \n IF ( b >= 0 ) error = -2 * c / (b + SQRT(delta))\n IF ( b < 0 ) error = -2 * c / (b - SQRT(delta))\n x_n = x_n_1 + error \n\n ! debug \n IF ( PRESENT(debug) .AND. debug == 1 ) & \n PRINT 2000, nstep, x_n, f(x_n), error \n\n ! termination\n x_n_3 = x_n_2\n x_n_2 = x_n_1\n x_n_1 = x_n\n error = ABS(error) \n IF ( error < TOLERANCE ) THEN \n MUELLER = x_n\n RETURN \n END IF \n END DO\n\n 1000 FORMAT (A3, (A10, 3X), A13, 4X, A13)\n 2000 FORMAT (I3, F13.6, 2(4X, ES13.6))\n END FUNCTION MUELLER\n\nEND MODULE ROOT\n", "meta": {"hexsha": "b63573fb5dd0cfd927dc5bc5277196e74850b17d", "size": 8587, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "root.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": "root.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": "root.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.7867867868, "max_line_length": 105, "alphanum_fraction": 0.4335623617, "num_tokens": 2847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.9005297921244243, "lm_q1q2_score": 0.8193983603997947}} {"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 cholesky(nn, n, A, G)\n implicit double precision(a-h,o-z)\n dimension A(nn,nn)\n dimension G(nn,nn)\n\n ! Light check of positive definite\n\n\n ! [1]\n G(:,:)=0.0d0\n do j = 1, n\n\n\n\n G(j,j) = dsqrt( A(j,j) - dot_product(G(j,1:j-1),G(j,1:j-1)) )\n do i = j+1, n\n G(i,j) = ( A(i,j) - dot_product(G(i,1:j-1),G(j,1:j-1)) ) / G(j,j)\n end do\n end do\n\n end subroutine\n", "meta": {"hexsha": "7516dfa2fca5001b5a364dd2f558f967e62e1217", "size": 1272, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/ag_ho/cholesky.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/cholesky.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/cholesky.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": 31.0243902439, "max_line_length": 91, "alphanum_fraction": 0.6061320755, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8192873136049853}} {"text": "program test_integrals\n !! program to show the usage of the *integrals* module\n use integrals, only : trapz, quad\n implicit none\n\n\n real, parameter :: pi = acos(-1.)\n real :: a, b, h, Int\n integer :: i\n\n a = 0.\n b = 2*pi\n h = 0.001\n\n\n\n Int = quad( f, a, b, h, 'Trapezoidal' )\n print*, \"Integral of sin(x) between 0 and 2pi using the trapezoidal rule:\"\n print'(F6.3)', Int\n\n Int = quad( f, a, b, h, 'Simpson' )\n print*, \"Integral of sin(x) between 0 and 2pi using Simpson's rule:\"\n print'(F6.3)', Int\n\n a = 0.\n b = 1.\n h = 0.001\n\n Int = quad( g, a, b, h,'Trapezoidal' )\n print*, \"Integral of x^4 between 0 and 1 using the trapezoidal rule:\"\n print'(F6.3)', Int\n\n Int = quad( g, a, b, h, 'Simpson' )\n print*, \"Integral of x^4 between 0 and 1 using Simpson's rule:\"\n print'(F6.3)', Int\n\n Int = quad( g, 0., 1., h, 'Muller' )\n\ncontains\n function f(x) result(y)\n real, intent(in) :: x\n real :: y\n y = sin(x)\n end function\n\n function g(x) result(y)\n real, intent(in) :: x\n real :: y\n y = x**4\n end function\n\nend program\n", "meta": {"hexsha": "e781cac01efea288fa5f5c8f8b565c47ffdfde55", "size": 1061, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/test_integrals.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/test_integrals.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/test_integrals.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": 20.0188679245, "max_line_length": 76, "alphanum_fraction": 0.5843543827, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985937, "lm_q2_score": 0.8705972801594707, "lm_q1q2_score": 0.8190489954612505}} {"text": "RECURSIVE FUNCTION fact(n) RESULT(answer)\r\n!\r\n! Purpose:\r\n! To calculate the factorial function\r\n! | n(n-1)! n >= 1 \r\n! n ! = |\r\n! | 1 n = 0\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/07/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) :: n ! Value to calculate\r\nINTEGER :: answer ! Result variable\r\n\r\nIF ( n >= 1 ) THEN\r\n answer = n * fact(n-1)\r\nELSE\r\n answer = 1\r\nEND IF\r\n\r\nEND FUNCTION fact\r\n", "meta": {"hexsha": "a6f57eab712df80d3493db32dc5da32cf8157328", "size": 683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap13/fact.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/chap13/fact.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/chap13/fact.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": 25.2962962963, "max_line_length": 65, "alphanum_fraction": 0.4890190337, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.8186350980718978}} {"text": "! for more info refer : https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap02/funct.html\r\nprogram intrinsicfunction\r\n\r\n! CTM is most of the Mathematical function the argument must be real\r\n\r\nprint *, \"abs(-5) : \", abs(-5); ! argument can be integer/real\r\nprint *, \"abs(25.14) : \", abs(25.14);\r\nprint *, \"mod(10, 2) : \", mod(10, 2);\r\nprint *, \"mod(17, 3) : \", mod(10, 2);\r\nprint *, \"sqrt(16.0) : \", sqrt(16.0);\r\nprint *, \"sqrt(13) : \", sqrt(13.5);\r\nprint *, \"exp(3) : \", exp(3.0); ! base e (euler e = 2.718)\r\nprint *, \"log(10) : \", log(10.0);\r\nprint *, \"int(12.41) : \", int(12.41); ! gives integer part\r\nprint *, \"nint(11.43) : \", nint(11.43);\r\nprint *, \"nint(11.63) : \", nint(11.63);\r\nprint *, \"fraction(11.43) : \", fraction(11.43);\r\nprint *, \"floor(11.43) : \", floor(11.43);\r\nprint *, \"floor(11.93) : \", floor(11.93);\r\nprint *, \"real(10) : \", real(10);\r\nprint *, \"max(3, 44, 54) : \", max(3, 44, 54);\r\nprint *, \"min(3, 44, 54) : \", min(3, 44, 54);\r\nprint *, \"max(3.4, 6.1, 5.6) : \", max(3.4, 6.1, 5.6);\r\nprint *, \"min(3.4, 6.1, 5.6) : \", min(3.4, 6.1, 5.6);\r\n\r\nend program intrinsicfunction", "meta": {"hexsha": "9364662d529a4dd364a21ed71a777a197874c6cc", "size": 1226, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/instrinsicFunction.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/instrinsicFunction.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/instrinsicFunction.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": 47.1538461538, "max_line_length": 91, "alphanum_fraction": 0.4926590538, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811631528336, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.8186121046079473}} {"text": "program Find_series !求级数,其中为了精度要求定义了常数error。\r\nimplicit none\r\n real, parameter:: error = 1E-5\r\n\tinteger:: n , i\r\n real:: a , y , delta\r\n read*, n\r\n\r\n a = 0\r\n\tdo i = 1 , n\r\n\tdelta = 1. / (i * (i + 1.))\r\n if ( abs(delta) <= error) exit\r\n\ty = a + delta\r\n\ta = y\r\n\tend do\r\n\t\r\n\twrite(*,\"(a,F8.5)\") \"sum=\" , y\r\nend\r\n", "meta": {"hexsha": "de8f43db6534e5e5dc148f3b2e7e1f5ab62d9e4d", "size": 339, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/1096.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/1096.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/1096.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": 18.8333333333, "max_line_length": 60, "alphanum_fraction": 0.4778761062, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.8182816987009393}} {"text": "PROGRAM least_squares_fit\r\n!\r\n! Purpose:\r\n! To perform a least-squares fit of an input data set\r\n! to a straight line, and print out the resulting slope\r\n! and intercept values. The input data for this fit\r\n! comes from a user-specified input data file.\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 constants \r\nINTEGER, PARAMETER :: LU = 18 ! I/o unit for disk I/O\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\n! Note that cumulative variables are all initialized to zero.\r\nCHARACTER(len=24) :: filename ! Input file name (<= 24 chars)\r\nINTEGER :: ierror ! Status flag from I/O statements\r\nINTEGER :: n = 0 ! Number of input data pairs (x,y)\r\nREAL :: slope ! Slope of the line\r\nREAL :: sum_x = 0. ! Sum of all input X values\r\nREAL :: sum_x2 = 0. ! Sum of all input X values squared\r\nREAL :: sum_xy = 0. ! Sum of all input X*Y values\r\nREAL :: sum_y = 0. ! Sum of all input Y values\r\nREAL :: x ! An input X value\r\nREAL :: x_bar ! Average X value\r\nREAL :: y ! An input Y value\r\nREAL :: y_bar ! Average Y value\r\nREAL :: y_int ! Y-axis intercept of the line\r\n\r\n! Prompt user and get the name of the input file.\r\nWRITE (*,1000)\r\n1000 FORMAT (1X,'This program performs a least-squares fit of an ',/, &\r\n 1X,'input data set to a straight line. Enter the name',/ &\r\n 1X,'of the file containing the input (x,y) pairs: ' )\r\nREAD (*,1010) filename\r\n1010 FORMAT (A)\r\n\r\n! Open the input file\r\nOPEN (UNIT=LU, FILE=filename, STATUS='OLD', IOSTAT=ierror )\r\n\r\n! Check to see of the OPEN failed.\r\nerrorcheck: IF ( ierror > 0 ) THEN \r\n\r\n WRITE (*,1020) filename\r\n 1020 FORMAT (1X,'ERROR: File ',A,' does not exist!')\r\n\r\nELSE\r\n \r\n ! File opened successfully. Read the (x,y) pairs from \r\n ! the input file.\r\n DO \r\n READ (LU,*,IOSTAT=ierror) x, y ! Get pair\r\n IF ( ierror /= 0 ) EXIT\r\n n = n + 1 !\r\n sum_x = sum_x + x ! Calculate \r\n sum_y = sum_y + y ! statistics\r\n sum_x2 = sum_x2 + x**2 !\r\n sum_xy = sum_xy + x * y !\r\n END DO\r\n \r\n ! Now calculate the slope and intercept. \r\n x_bar = sum_x / real(n)\r\n y_bar = sum_y / real(n)\r\n slope = (sum_xy - sum_x * y_bar) / ( sum_x2 - sum_x * x_bar)\r\n y_int = y_bar - slope * x_bar \r\n \r\n ! Tell user.\r\n WRITE (*, 1030 ) slope, y_int, N\r\n 1030 FORMAT ('0','Regression coefficients for the least-squares line:',&\r\n /,1X,' slope (m) = ', F12.3,&\r\n /,1X,' Intercept (b) = ', F12.3,&\r\n /,1X,' No of points = ', I12 )\r\n \r\n ! Close input file, and quit.\r\n CLOSE (UNIT=LU)\r\n\r\nEND IF errorcheck\r\n\r\nEND PROGRAM least_squares_fit\r\n", "meta": {"hexsha": "1bb23738ea2b36bc2aa689cd562444a9a7144a2c", "size": 3056, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap5/least_squares_fit.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/chap5/least_squares_fit.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/chap5/least_squares_fit.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.9529411765, "max_line_length": 76, "alphanum_fraction": 0.5487565445, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661028358094, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.8182816910514178}} {"text": "program square_root\nimplicit none\n\nreal(kind=8) :: A, root, temp_root, int1, int2, dec1, dec2, n_decimal\ninteger :: i, j, N, integer_part\n\nwrite(*,*) 'number?'\nread(*,*) A\n\n!-------------------------------------------\n! For the integer part of the square root:\n!-------------------------------------------\n\nN = nint(A) ! just because we need an integer for the do loop below\ndo i = 0, N \n int1 = dble(i)\n int2 = int1 + 1.0d0\n if (int2*int2 .gt. A) then\n if (int1*int1 .le. A) then\n root = int1 !at this point we have the integer part of the root\n exit\n end if\n end if\nend do\n\n!------------------------------------------\n! For the decimal part of the square root:\n!------------------------------------------\n\nn_decimal = 1.0d0\ndo j = 1, 16 !level of precision\n n_decimal = n_decimal/10.0 !moving to the right by one decimal place\n write(*,'(A5I4)') 'j', j\n do i = 0, 9 !the digit at the j-th decimal place can have values\n ! from 0 to 9\n dec1 = root + dble(i)*n_decimal\n dec2 = root + dble(i + 1)*n_decimal\n write(*,'(I3)', advance='no') i\n write(*,*) dec1, dec2\n if (dec2*dec2 .gt. A) then\n if(dec1*dec1 .le. A) then\n root = dec1 ! and now we have the square root with precision j\n exit\n end if\n end if\n end do\n write(*,*)\nend do\n\nwrite(*,*) root\n\nend program square_root\n", "meta": {"hexsha": "ca7df6dffbad09bdaf00b5a508c98e8c0fe03fbe", "size": 1401, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "sqrt/sqrt.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/sqrt.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/sqrt.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": 26.4339622642, "max_line_length": 74, "alphanum_fraction": 0.5174875089, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759488, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8181764466490024}} {"text": "! ---- numerical methods\nmodule num_utils\n implicit none\n\ncontains\n ! =========================\n ! Root Finding Algorithms\n ! =========================\n\n ! Bisection method\n subroutine bisect(xa, xb, tol, xroot, Fun)\n real, intent(in) :: xa, xb, tol ! limits and accuracy\n real, intent(out):: xroot ! root\n integer :: N ! number of bisections\n \n interface\n function Fun(X)\n real :: Fun\n real, intent(in) :: X \n end function Fun \n end interface\n\n real :: xl, xr\n integer :: i\n\n ! Initialize\n xl = xa\n xr = xb\n ! Number of iteration required\n N = nint(log(abs(xa-xb)/tol) / log(2.0) + 1)\n\n do i=1, N\n xroot = (xl + xr) / 2\n if(Fun(xl) * Fun(xroot) > 0) then\n xl = xroot\n else\n xr = xroot\n end if\n end do\n end subroutine bisect\n\n ! Newton method for root finding\n subroutine newtonRoot(x0, tol, xroot, fn, dfn)\n real, intent(in) :: x0, tol\n real, intent(out) :: xroot\n !integer :: niter\n interface\n real function fn(x)\n real, intent(in) :: x\n end function fn\n\n real function dfn(x)\n real, intent(in) :: x\n end function dfn\n end interface\n ! Local variable\n real :: x\n\n x = x0 \n !niter = 0\n do\n !niter = niter + 1\n if(abs(fn(x)) >= abs(tol)) then\n x = x - fn(x) / dfn(x)\n else\n exit\n end if\n end do\n xroot = x\n end subroutine newtonRoot\n\n ! =====================\n ! Integration methods\n ! =====================\n function trapezoid(xa, xb, h, Fn) result(ans)\n interface\n real function Fn(x)\n real, intent(in) :: x\n end function Fn \n end interface\n real :: ans\n real, intent(in) :: xa, xb, h\n\n ! Local variables\n integer :: i, N\n\n N = nint((xb - xa)/h)\n\n ans = 0.0\n do i=1, N\n ans = ans + Fn(xa + i*h)\n end do\n ans = h / 2.0 * (Fn(xa) + Fn(xb) + 2 * ans)\n\n end function trapezoid\n\n ! -------------\n ! Simpson Rule\n ! -------------\n function simpson(xa, xb, h, Fn) result(ans)\n interface\n real function Fn(x)\n real, intent(in) :: x\n end function Fn\n end interface\n real, intent(in) :: xa, xb, h\n real :: ans\n ! Local variables\n integer :: i, N\n\n ans = 0.0\n N = nint((xb - xa)/(2.0*h))\n\n do i=1, N-1\n ans = ans + 2.0 * Fn(xa + 2.0*i * h)\n end do\n do i=1, N\n ans = ans + 4.0*Fn(xa + (2*i-1)*h)\n end do\n\n ans = h/3.0 * (Fn(xa) + Fn(xb) + ans)\n end function simpson\n\n\nend module num_utils\n", "meta": {"hexsha": "aa2d4457309c890d901558b0170dc82ffdb54487", "size": 3001, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/numeth.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/numeth.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/numeth.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": 23.8174603175, "max_line_length": 65, "alphanum_fraction": 0.4231922692, "num_tokens": 825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8791467801752451, "lm_q1q2_score": 0.8180093844911633}} {"text": "subroutine thomas(a,b,c,d,z,n,k) ! \"Llewellyn Thomas\" algorithm for tridiagonal banded matrices\"\n! Adapted from https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm\nINTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\ninteger, INTENT(IN) :: n,k\nreal(wp), INTENT(INOUT) :: a(n),b(n),c(n),d(n,k)\nreal (wp), INTENT(OUT) :: z(n,k)\nreal(wp) :: g\ninteger i\ndo i=2,n\n g=a(i)/b(i-1)\n b(i)= b(i)-g*c(i-1)\n d(i,:)=d(i,:)-g*d(i-1,:)\nend do\n z(n,:)= d(n,:)/b(n)\ndo i=n-1,1,-1\n z(i,:)=(d(i,:)-c(i)*z(i+1,:))/b(i)\nend do \nreturn\nend subroutine thomas\n", "meta": {"hexsha": "c9a5b3cd521b00c6f5a699b0101aded1550698e9", "size": 549, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "thomas.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": "thomas.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": "thomas.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": 27.45, "max_line_length": 96, "alphanum_fraction": 0.621129326, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9693241956308278, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.8180079357720634}} {"text": "! Created by EverLookNeverSee@GitHub on 5/19/20.\n! This subroutine computes factorial of n using recursion.\n\nrecursive subroutine recursive_factorial(n, fact)\n ! declaring variables\n integer :: n ! input value\n integer :: fact ! output value\n ! exit point\n if (n == 1) then\n fact = 1\n else\n call recursive_factorial((n - 1), fact)\n fact = n * fact\n end if\nend subroutine recursive_factorial", "meta": {"hexsha": "ee8a02902617ed256deb549210ef76243fcfbde2", "size": 443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/recursive_factorial.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/recursive_factorial.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/recursive_factorial.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.5333333333, "max_line_length": 58, "alphanum_fraction": 0.6501128668, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.8179160814202425}} {"text": "program interpol_main\n use nrtype\n use interpolation\n implicit none\n real(dp) :: y, dy, x, grid(2,2,2), xyz(3)\n real(dp) :: xi(6), yi(6), yi2(6), yi3(6), yi4(6)\n integer :: i, j, idx(3)\n\n x = -5._dp\n xi = [-5.0_dp,-2.2_dp,1._dp,2.2_dp,8.6_dp,9.3_dp]\n yi = [-8.7_dp,2._dp,4._dp,10.3_dp,-4.67_dp,8.6_dp]\n\n yi2 = rational(xi)\n\n call csplinec(xi,yi,yi3)\n call csplinec(xi,yi,yi4)\n\n open(unit = 1, file = \"poly_int.dat\")\n open(unit = 2, file = \"rat_int.dat\")\n open(unit = 3, file = \"cspline_int.dat\")\n open(unit = 4, file = \"cspline_rat_int.dat\")\n open(unit = 5, file = \"trilinear.dat\")\n\n do while (x < 9.3_dp)\n call pinex(xi,yi,x,y,dy)\n write(1,*) x, y\n\n call rinex(xi,yi2,x,y,dy)\n write(2,*) x, y, rational(x)\n\n call csplnei(xi, yi, yi3, x, y)\n write(3,*) x, y\n\n call csplnei(xi, yi2, yi4, x, y)\n write(4,*) x, y\n\n x = x + 0.1_dp\n end do\n close(1); close(2); close(3); close(4)\n\n ! Testing trilinear interpolation.\n grid = 1._dp\n xyz = [1.5_dp,1.5_dp,1.5_dp]\n idx = floor(xyz)\n ! Should print 1\n print*, cctrilinint(grid, xyz, idx, 1._dp)\n ! Test successful!\n\n grid(1,1,1) = 0.\n grid(1,2,1) = 0.\n grid(2,1,1) = 0.\n grid(1,1,2) = 0.\n grid(2,2,1) = 1.\n grid(2,1,2) = 1.\n grid(1,2,2) = 1.\n grid(2,2,2) = 1.\n xyz = [1.9_dp,1.9_dp,1.9_dp]\n idx = floor(xyz)\n ! Should print 0.972\n print*, cctrilinint(grid, xyz, idx, 1._dp)\n ! Test successful!\n\ncontains\n\n elemental function rational(x)\n implicit none\n real(dp), intent(in) :: x\n real(dp) :: rational\n\n rational = ( x*x*x - 2._dp * x ) / ( 2._dp*(x*x - 5._dp) )\n end function rational\nend program interpol_main\n", "meta": {"hexsha": "6b6ff44f08a648e2390c5af8e7300cd6ef538e12", "size": 1650, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "interpolation/interpol_main.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_main.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_main.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": 22.602739726, "max_line_length": 62, "alphanum_fraction": 0.5739393939, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.8177397523037159}} {"text": "! Created by EverLookNeverSee@GitHub on 6/12/20\n! For more information see FCS/img/Exercise_14_Alternative.png\n! I could not have done it without `Stavros Meskos`\n\nmodule m_cardano\n implicit none\n private ! makes this module private\n ! makes these entities accessible from outside of the module\n public t_cubic_solution, solve\n\n ! defining a derived type\n type t_cubic_solution\n real :: x_1 ! real root of equation\n complex :: z_2 ! first complex root\n complex :: z_3 ! second complex root\n end type t_cubic_solution\n\n contains\n pure type(t_cubic_solution) function solve(a, b, c, d) result(res)\n ! declaring dummy parameters and local variables\n real, intent(in) :: a, b, c, d\n real :: Q, R, S, T, r_part, i_part, temp\n\n ! calculating values of Q and R\n Q = (3.0*a*c - b**2) / (9.0 * a**2)\n R = (9.0*a*b*c - 27.0*d* a**2 - 2.0 * b**3) / (54.0 * a**3)\n\n ! using temp adjunct variable and abs intrinsic function in order to\n ! prevent `negative real to a real power` error\n temp = R + sqrt(Q**3 + R**2)\n S = sign(1.0, temp) * abs(temp)**(1.0 / 3.0)\n temp = R - sqrt(Q**3 + R**2)\n T = sign(1.0, temp) * abs(temp)**(1.0 / 3.0)\n\n ! calculating real and imaginary parts of complex roots\n r_part = -(s + t) / 2.0 - b / (3.0 * a)\n i_part = (sqrt(3.0) / 2.0) * (s - t)\n\n ! calculating and returning real and complex roots\n res%x_1 = S + T - b / (3.0 * a)\n res%z_2 = cmplx(r_part, i_part)\n res%z_3 = cmplx(r_part, -i_part)\n end function solve\nend module m_cardano\n\nprogram main\n use m_cardano ! importing module\n implicit none\n ! declaring variables\n real :: a, b, c, d\n type(t_cubic_solution) :: roots\n\n print *, \"Cardano's solution for solving cubic equation\"\n print *, \"Cubic equation: ax^3 + bx^2 + cx + d = 0\"\n print *, \"Enter coefficients: a, b, c, d respectively:\"\n ! getting coefficients of cubic equation using user input\n read *, a, b, c, d\n ! calling solve function\n roots = solve(a, b, c, d)\n ! printing results\n print *, \"Roots:\", roots\nend program main", "meta": {"hexsha": "cb0ae64da03635937c01f37ea565df0be04dd6c9", "size": 2279, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_14.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_14.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_14.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.7580645161, "max_line_length": 80, "alphanum_fraction": 0.5774462484, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.8176321854588511}} {"text": "subroutine rayleigh (a, u, xlam, eps, nmaxit, ier)\n\n implicit none\n\n real, dimension(:,:), intent(in) :: a\n real, dimension(:), intent(out) :: u\n real, intent(inout) :: xlam\n real, intent(in) :: eps\n integer, intent(in) :: nmaxit\n integer, intent(inout) :: ier\n\n real,dimension(:), allocatable :: v\n\n integer :: n, iter, i, j\n real :: xn , s, xlam1, xlam2\n\n n = size(a(1,:))\n\n allocate(v(n))\n\n u = 0\n u(1) = 1\n\n do iter= 1, nmaxit\n do i =1, n\n v(i) = 0\n do j = 1,n\n v(i) = v(i) + a(i,j)*u(j)\n end do\n end do\n s = 0\n xn = 0\n do i =1,n\n s = s + u(i)*v(i)\n xn = xn + v(i)*v(i)\n end do\n xn = sqrt(xn)\n do i = 1, n\n u(i) = v(i)/xn\n end do\n xlam2 = s\n if(iter .ne. 1) then\n if(abs(xlam2 - xlam1)/(abs(xlam1) + 1)<= eps) then\n xlam = xlam2\n ier = 1\n return !salimos\n end if\n end if\n xlam1 = xlam2\n end do\n xlam = xlam2\n ier = 2\n\nend subroutine\n", "meta": {"hexsha": "004b71b035e9a0da23296c8e6b0673b2faa6b3d6", "size": 1016, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica5_potencia/rayleigh.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": "Practica5_potencia/rayleigh.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": "Practica5_potencia/rayleigh.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": 18.4727272727, "max_line_length": 58, "alphanum_fraction": 0.4645669291, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8723473846343393, "lm_q1q2_score": 0.8175733796716498}} {"text": "program laplace\n integer,parameter :: N1=64, N2=64\n real(8),parameter :: PI = 3.141592653589793238463\n\n integer :: niter=100\n real(8) :: u(N1,N2),uu(N1,N2)\n real(8) :: value = 0.0\n\n do j=1,N2\n do i=1,N1\n u(i,j)=0.0\n uu(i,j)=0.0\n end do\n end do\n \n do j=2,N2-1\n do i=2,N1-1\n u(i,j)=sin(dble(i-1)/N1*PI)+cos(dble(j-1)/N2*PI)\n end do\n end do\n \n do k=1,niter\n\n do j=2,N2-1\n do i=2,N1-1\n uu(i,j)=u(i,j)\n end do\n end do\n\n do j=2,N2-1\n do i=2,N1-1\n u(i,j)=(uu(i-1,j) + uu(i+1,j) + uu(i,j-1) + uu(i,j+1))/4.0\n end do\n end do\n\n enddo\n\n do j=2,N2-1\n do i=2,N1-1\n value = value + dabs(uu(i,j) -u(i,j))\n end do\n end do\n \n print *, 'Verification =', value\n\nend program laplace\n", "meta": {"hexsha": "b715478ce4980a8a8a2f22e32c1e4f4a250f15f0", "size": 796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "beginner/2.globalview/laplace.f90", "max_stars_repo_name": "XcalableMP/lecture", "max_stars_repo_head_hexsha": "723ef4499fbbce70893d3fbd076e8c3e86d11a50", "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": "beginner/2.globalview/laplace.f90", "max_issues_repo_name": "XcalableMP/lecture", "max_issues_repo_head_hexsha": "723ef4499fbbce70893d3fbd076e8c3e86d11a50", "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": "beginner/2.globalview/laplace.f90", "max_forks_repo_name": "XcalableMP/lecture", "max_forks_repo_head_hexsha": "723ef4499fbbce70893d3fbd076e8c3e86d11a50", "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": 16.9361702128, "max_line_length": 69, "alphanum_fraction": 0.4811557789, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778024535094, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.8174317200737493}} {"text": "! file: euler002.f90\n! author: Marvin Smith\n! date: 4/25/2015\n!\n! Purpose: Solves Project Euler 002 using Fortran 90\n!\n\nPROGRAM Euler002\n USE FibonacciModule\n IMPLICIT none\n INTEGER :: sum, counter, temp_value, max_fib_number, Fmax\n\n! Set running sum (Start with 2 as that is automatic)\nsum = 0\n\n! Define the max value to find fibonacci numbers for\nmax_fib_number=4000000\n\n! Find the max Fn such that it is closest but less than max\nFmax = Find_Max_Fibonacci( max_fib_number )\n\n! Start Iterating over Fibonacci Values\ndo counter = 2, Fmax\n\n ! Call the fibonacci number for the current counter\n temp_value = Fibonacci(counter)\n \n ! Check if it is even\n if (MODULO(temp_value,2) == 0) then\n sum = sum + temp_value\n endif\n\nend do\n\n! Print the Sum\nprint*, sum\n\n! Exit Program\nend\n\n\n\n", "meta": {"hexsha": "653a70148013e322fbc1d6f384f34e96392c1b2e", "size": 841, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/euler002/euler002.f90", "max_stars_repo_name": "marvins/ProjectEuler", "max_stars_repo_head_hexsha": "55a377bb9702067bac6908c1316c578498402668", "max_stars_repo_licenses": ["MIT"], "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/euler002/euler002.f90", "max_issues_repo_name": "marvins/ProjectEuler", "max_issues_repo_head_hexsha": "55a377bb9702067bac6908c1316c578498402668", "max_issues_repo_licenses": ["MIT"], "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/euler002/euler002.f90", "max_forks_repo_name": "marvins/ProjectEuler", "max_forks_repo_head_hexsha": "55a377bb9702067bac6908c1316c578498402668", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-16T09:25:19.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-16T09:25:19.000Z", "avg_line_length": 19.5581395349, "max_line_length": 61, "alphanum_fraction": 0.6848989298, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777975782055, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.8174317194695498}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Suma de matrices\n!Descripción: Suma dos matrices\n!Fecha: 30/03/2020\n\nProgram sumat\n implicit none\n REAL, allocatable, dimension(:, :)::A, B, C\n iNTEGER, dimension(0:1)::N, M\n REAL::s, t\n INTEGER::i, j, k\n WRITE(*, *) \"Dimensión de la primera matriz (filas x columnas)\"\n READ(*, *) N(0), N(1)\n WRITE(*, *) \"Dimensión de la segunda matriz (filas x columnas)\"\n READ(*, *) M(0), M(1)\n if ((N(0) .eq. M(0)) .and. (N(1) .eq. M(1))) then\n allocate(A(1:N(0), 1:N(1)), B(1:N(0), 1:N(1)), C(1:N(0), 1:N(1)))\n WRITE(*, *) \"Elementos de la primera matriz:\"\n do i=1, N(0)\n do j=1, N(1)\n READ(*, *) A(i, j)\n end do\n end do\n WRITE(*, *) \"Elementos de la segunda matriz:\"\n do i=1, N(0)\n do j=1, N(1)\n READ(*, *) B(i, j)\n end do\n end do\n do i=1, N(0)\n do j=1, N(1)\n C(i, j)=A(i, j)+B(i, j)\n end do\n end do\n WRITE(*, *) \"Suma:\"\n do i=1, N(0)\n WRITE(*, *) C(i, :)\n end do\n deallocate(A, B, C)\n end if\nend Program sumat\n\n\n\n", "meta": {"hexsha": "59487cf3b7423b7a5c845bdb5d79c6ab7b16eaa8", "size": 1093, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "19.- SumaMat/SumaMat.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": "19.- SumaMat/SumaMat.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": "19.- SumaMat/SumaMat.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": 24.2888888889, "max_line_length": 70, "alphanum_fraction": 0.4986276304, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.9046505376715775, "lm_q1q2_score": 0.8171655944805206}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Chicharronera\n!Descripción: Calcula las raíces de una ecuación cuadrárica por medio de la fórmula general\n!Fecha: 15/03/2020\n\nProgram EQN2 !Inicio del programa\n implicit none !Desactivar variables implícitas\n REAL::A, B, C, X1, X2, X, D !Declaración de variables reales\n COMPLEX::Y1, Y2 !Declaración de variables complejas\n write(*, *) \"Dame los coeficientes de la ecuación de la forma Ax^2+Bx+C=0\" !Pedir coeficientes\n read(*, *) A, B, C !Ingresar coeficientes\n D=B**2-4.0*A*C !Discriminante\n if (D<0) then !Validación del discriminante si es menor que cero\n Y1=COMPLEX(-B/(2.0*A), D/(2.0*A)) !Primera raíz compleja\n Y2=COMPLEX(-B/(2.0*A), -D/(2.0*A)) !Segunda raíz compleja\n write(*, *) \"Raíces complejas\" \n write(*, *) \"X1=\", Y1\n write(*, *) \"X2=\", Y2 \n else if (D==0) then !Validación del discrimiante si es igual que cero\n X=-B/(2.0*A) !Raíces iguales\n write(*, *) \"Raíces repetidas\"\n write(*, *) \"X1=X2=\", X\n else !Validación del discriminante si es mayor que cero\n X1=(-B+D)/(2.0*A) \n X2=(-B-D)/(2.0*A)\n write(*, *) \"Raíces reales diferentes\"\n write(*, *) \"X1=\", X1\n write(*, *) \"X2=\", X2\n end if\nend Program EQN2 !Final del programa\n\n\n", "meta": {"hexsha": "c78200537e56e36ac4c3fd881d4a559390995f11", "size": 1257, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "3.- Chicharronera/EQN2.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": "3.- Chicharronera/EQN2.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": "3.- Chicharronera/EQN2.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": 38.0909090909, "max_line_length": 96, "alphanum_fraction": 0.6435958632, "num_tokens": 477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8170338609038459}} {"text": "module routines\nimplicit none\ncontains\n\nsubroutine writes (A)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A\n integer :: n, m, i, j, k\n\n n = size(A, 1)\n m = size(A, 2)\n\n write(*,*) \n do i = 1,n\n write(*,'(20F8.3)') (A(i,j), j = 1, m)\n end do\nend subroutine writes\n\nsubroutine MatrixMult (A, B)\n real(kind=8), allocatable, dimension(:,:), intent(in) :: A, B\n real(kind=8), allocatable, dimension(:,:) :: M\n integer :: i, j, k, a1, a2, b1, b2\n\n a1 = size(A, 1)\n a2 = size(A, 2)\n b1 = size(B, 1)\n b2 = size(B, 2)\n\n if (a2 .ne. b1) then\n write(*,*) \"The matrices cannot be multiplied since the number of rows in [b] is not equal to the number of columns in [a].\"\n else if ( a2 .eq. b1) then\n allocate (M(a1,b2))\n\n do i = 1, a1\n do j = 1, b2\n M(i,j) = 0.0d0\n do k = 1, a2\n M(i,j) = M(i,j) + A(i,k)*B(k,j)\n end do\n end do\n end do\n\n call writes (M)\n\n deallocate (M)\n end if\nend subroutine MatrixMult\n\n\n\n\n\n\nend module routines\n", "meta": {"hexsha": "187a1c03ea1879dd9031455e574ecc6a02b6834f", "size": 1067, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW2/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/HW2/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/HW2/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": 19.7592592593, "max_line_length": 130, "alphanum_fraction": 0.5210871603, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8840392710530071, "lm_q1q2_score": 0.8169776608836191}} {"text": "module linear_solvers\n !! Module for computing solutions to linear systems of the form:\n !! $$\\mathbf{A}\\mathbf{x}=\\mathbf{b}$$\n implicit none\n\n contains\n\n function solve_U(U,b) result(x)\n !! Computes the solution of an upper triangular system:\n !! $$ \\mathbf{U}\\mathbf{x} = \\mathbf{b}$$\n real, intent(in) :: U(:,:)\n !! Upper triangular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real :: x(size(U,2))\n !! Solution vector **x**\n\n integer :: i, N\n\n N = size(U,2)\n\n x(N) = b(N)/U(N,N)\n\n do i=N-1,1,-1\n x(i) = ( b(i) - dot_product(U(i,i+1:N),x(i+1:N)))/U(i,i)\n end do\n\n end function\n\n\n function solve_L(L,b) result(x)\n !! Computes the solution of a lower triangular system:\n !! $$ \\mathbf{L}\\mathbf{x} = \\mathbf{b}$$\n real, intent(in) :: L(:,:)\n !! Lower triangular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real :: x(size(L,2))\n !! Solution vector **x**\n\n integer :: i, N\n\n N = size(L,2)\n\n x(1) = b(1)/L(1,1)\n\n do i=2,N\n x(i) = ( b(i) - dot_product(L(i,1:i-1),x(1:i-1)))/L(i,i)\n end do\n\n end function\n\n\n subroutine make_U(M)\n !! Takes the extended matrix M = (A|b)\n !! and makes it upper triangular.\n real, intent(inout) :: M(:,:)\n !! Extended matrix (A|b)\n integer :: N, i, j, imax\n real :: Q\n\n real :: temp(size(M,2))\n\n N = size(M,1)\n do j = 1, N-1\n ! row swapping for stability\n imax = MAXLOC(abs(M(j:N,j)),1) + (j - 1)\n temp = M(j,:)\n M(j,:) = M(imax,:)\n M(imax,:) = temp\n ! triangularization of column j\n do i = j+1, N\n Q = M(i,j)/M(j,j)\n M(i,:) = M(i,:) - Q*M(j,:)\n end do\n end do\n\n end subroutine\n\n\n\n\n function gauss_solve(A,b) result(x)\n !! Computes the solution of the system:\n !! $$\\mathbf{A}\\mathbf{x}=\\mathbf{b}$$\n !! where **A** is a non-singular matrix.\n real, intent(in) :: A(:,:)\n !! Non-singular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real :: x(size(A,2))\n !! Solution vector **x**\n\n real :: M(size(A,1),size(A,2)+1)\n integer :: N\n\n N = size(A,2)\n M(:,1:N) = A\n M(:,N+1) = b\n\n call make_U(M)\n\n x = solve_U(M(:,1:N),M(:,N+1))\n end function\n\n\n\n subroutine factor_LU(A,L,U)\n !! Computes de LU factorization of a non-singular matrix **A**\n !! $$\\mathbf{A}=\\mathbf{L}\\mathbf{U}$$\n real, intent(in) :: A(:,:)\n !! Non-singular matrix\n real, intent(out) :: L(size(A,1),size(A,2))\n !! Lower triangular matrix\n real, intent(out) :: U(size(A,1),size(A,2))\n !! Upper triangular matrix\n\n integer :: N, i, j, k\n\n N = size(A,2)\n\n L = 0\n U = 0\n\n do k = 1, N\n\n do j = k, N\n U(k,j) = A(k,j) - dot_product(L(k,1:k-1),U(1:k-1,j))\n end do\n\n L(k,k) = 1\n do i = k+1, N\n L(i,k) = ( A(i,k) - dot_product(L(i,1:k-1),U(1:k-1,k))) / U(k,k)\n end do\n\n end do\n\n end subroutine\n\n function solve_LU(L,U,b) result(x)\n !! Computes the solution to the system:\n !! $$\\mathbf{L}\\mathbf{U}\\mathbf{x}=\\mathbf{b}$$\n !! where **L** and **U** are the matrices obtained from\n !! a LU factorization.\n real, intent(in) :: L(:,:)\n !! Lower triangular matrix\n real, intent(in) :: U(:,:)\n !! Upper triangular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real :: x(size(b))\n !! Solution vector **x**\n\n x = solve_U(U,solve_L(L,b))\n\n end function\n\n function solve(A,b) result(x)\n !! Computes the solution to the system:\n !! $$\\mathbf{A}\\mathbf{x}=\\mathbf{b}$$\n !! using LU factorization.\n real, intent(in) :: A(:,:)\n !! Non-singular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real :: x(size(b))\n !! Solution vector **x**\n\n real :: L(size(A,1),size(A,2)), U(size(A,1), size(A,2)), Ap(size(A,1),size(A,2))\n\n call factor_LU(A,L,U)\n\n x = solve_LU(L,U,b)\n\n end function\n\n\n function Jacobi(A,b,x_0, maxIter, err_x) result(x)\n !! Computes the solution to the system\n !! $$\\mathbf{A}\\mathbf{x}=\\mathbf{b}$$\n !! using the Jacobi iterative method.\n real, intent(in) :: A(:,:)\n !! Non-singular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real, intent(in) :: x_0(:)\n !! Initial approximation for the iteration\n integer, intent(in) :: maxIter\n !! Maximum number of iterations\n real, intent(in) :: err_x\n !! Precision for the stop criterion\n real :: x(size(A,2))\n !! Solution vector **x**\n\n integer :: i, N\n real :: x_old(size(A,2)), L(size(A,1),size(A,2)),U(size(A,1),size(A,2)), D_inv(size(A,2))\n\n N = size(A,2)\n\n L = 0\n U = 0\n do i = 1, N\n L(i,1:i-1)=A(i,1:i-1)\n D_inv(i) = 1./A(i,i)\n U(i,i+1:N) = A(i,i+1:N)\n end do\n\n\n x_old = x_0\n do i = 1, maxIter\n x = -D_inv*MATMUL(L+U,x_old)+D_inv*b\n if ( norm2(x-x_old)/norm2(x) < err_x ) exit\n x_old = x\n end do\n if( i>maxIter ) print*, 'the maximum number of iteration was reached &\n & without obtaining convergence'\n end function\n\n function GaussSeidel(A,b,x_0, maxIter, err_x) result(x)\n !! Computes the solution to the system\n !! $$\\mathbf{A}\\mathbf{x}=\\mathbf{b}$$\n !! using the Gauss-Seidel iterative method.\n real, intent(in) :: A(:,:)\n !! Non-singular matrix\n real, intent(in) :: b(:)\n !! Right hand side vector\n real, intent(in) :: x_0(:)\n !! Initial approximation for the iteration\n integer, intent(in) :: maxIter\n !! Maximum number of iterations\n real, intent(in) :: err_x\n !! Precision for the stop criterion\n real :: x(size(A,2))\n !! Solution vector **x**\n\n integer :: i, N\n real :: x_old(size(A,2)), LD(size(A,1),size(A,2)), U(size(A,1),size(A,2))\n\n N = size(A,2)\n\n LD = 0\n U = 0\n do i = 1, N\n LD(i, 1:i) = A(i, 1:i)\n U (i,i+1:N) = A(i,i+1:N)\n end do\n\n\n x_old = x_0\n do i = 1, maxIter\n x = solve_L(LD,-MATMUL(U,x_old)+b)\n if ( norm2(x-x_old)/norm2(x) < err_x ) exit\n x_old = x\n end do\n if( i>maxIter ) print*, 'the maximum number of iteration was reached &\n & without obtaining convergence'\n end function\n\n\n\n\nend module\n", "meta": {"hexsha": "ee003c7094d556816dff153939938279ad3a7622", "size": 6496, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/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/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": "docs/src/linear_solvers.f08", "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": 24.6996197719, "max_line_length": 95, "alphanum_fraction": 0.5113916256, "num_tokens": 2087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.816871358510792}} {"text": " subroutine fd_insolation_inst(lyear,idayjl,isecdy,xlat,xlon, hr_dawn, hr_dylen, 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 6/2009\r\n\r\n\treal(4), parameter :: solar_constant=1366.2 !watts/m**2\r\n real(4), parameter :: pi=3.141592654\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\nc\treal(4) sunlat,sunlon,sundis,rr,H,sinh,Q,cosZ,hh,xlon,hr_dylen,hr_dawn,local_time,hr_dusk\r\n\treal(4) sunlat,sunlon,sundis,rr,H,cosZ,hh,xlon,hr_dylen,hr_dawn,local_time,hr_dusk\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 H = acos(rr);\r\n\thr_dylen=H*24./pi\r\n\thr_dawn=12.-hr_dylen/2.\r\n\thr_dusk=12.+hr_dylen/2.\r\n\tlocal_time=(isecdy/86400.*24.+xlon/360.*24.)\r\n\tif(local_time>24)local_time=local_time-24.\r\n\thh=local_time\r\n\tif((hh>hr_dawn .and. hh 1) rr= 1.\r\n if(rr<-1) rr=-1.\r\n H = acos(rr);\r\n\thr_dylen=H*24./pi\r\n\thr_dawn=12.-hr_dylen/2.\r\n\thr_dusk=12.+hr_dylen/2.\r\n\tlocal_time=(43200/86400.*24.+xlon/360.*24.)\r\n\tif(local_time>24)local_time=local_time-24.\r\n\thh=local_time\r\n\tif((hh>hr_dawn .and. hh\n\nSUBROUTINE VectAff(N,v1)\n implicit none\n INTEGER :: N, i\n REAL*8 :: v1(*)\n\n DO i = 1, N\n WRITE(*,*) i,':',v1(i)\n END DO\n write(*,*)''\n read(*,*)\n RETURN\nEND SUBROUTINE VectAff\n\n! Affiche le vecteur v1 et v2 \n! et leur différence et attend un \n\nSUBROUTINE VectAff2(N, v1, v2)\n implicit none\n INTEGER :: N, i\n REAL*8 :: v1(*), v2(*)\n\n DO i = 1, N\n WRITE(*,*) i,':',v1(i),v2(i), v2(i)-v1(i)\n END DO\n write(*,*)''\n read(*,*)\n RETURN\nEND SUBROUTINE VectAff2\n\n\n! Initialise la matrice A(N,M) à 0.0d0 (full matrix)\n\nSUBROUTINE MatInit(N, M, A)\n implicit none\n INTEGER :: N, M, i, j \n REAL*8 :: A(N,M)\n\n DO i = 1, N\n DO j = 1, M\n A(i,j) = 0.0D0\n END DO\n END DO\n RETURN \nEND SUBROUTINE MatInit\n\n! Initialise le vecteur v à 0.0d0\n\nSUBROUTINE VectInit(N, v)\n implicit none\n INTEGER :: N, i \n REAL*8 :: v(N)\n\n DO i = 1, N \n v(i) = 0.0D0\n END DO\n RETURN\nEND SUBROUTINE VectInit\n\n! Effectue y=a*x+y\n\nSUBROUTINE DAXPY(N, A, X, Y)\n implicit none\n INTEGER :: I, N\n REAL*8 :: A,X(N),Y(N)\n\n IF (A .EQ. 0.0) RETURN\n DO I = 1, N\n Y(I) = A*X(I) + Y(I)\n ENDDO\n RETURN\nEND SUBROUTINE DAXPY\n", "meta": {"hexsha": "5e1f90c7778d7e63cc97fb51c1d115f453511422", "size": 3141, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "student/tfe/common/matfun.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": "student/tfe/common/matfun.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": "student/tfe/common/matfun.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": 18.1560693642, "max_line_length": 61, "alphanum_fraction": 0.5240369309, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8887587875995482, "lm_q1q2_score": 0.8163073900972468}} {"text": "! heat2d2solvers.f90 \r\n!\r\n! FUNCTIONS:\r\n! heat2d2solvers - Entry point of console application.\r\n!\r\n\r\n!****************************************************************************\r\n!\r\n! PROGRAM: heat2d2solvers\r\n\r\n! by mehrdad baba hosein pour\r\n!\r\n! PURPOSE: Entry point for the console application.\r\n! beyond sky!\r\n!****************************************************************************\r\n\r\n\r\n program heat_equation\r\n\r\n implicit none\r\n integer :: nx,nt,ny,i,j,t,s,l,h !nx= nodes in x , ny=nodes in y\r\n real,parameter:: alpha=0.5\r\n real :: dx,dy,p,st,dt,ttime !ttime= total time \r\n real,allocatable,dimension(:,:)::u_old,u_new,x,y,upre,unow,ufut !upre=u previous !ufut=u in future\r\n \r\n print*,\"inter your length = \"\r\n read*,l\r\n print*,\"inter your hieght = \"\r\n read*,h\r\n print*,\"inter your nodes in x = \"\r\n read*,nx\r\n print*,\"inter your nodes in y = \"\r\n read*,ny\r\n nt=1500 !time stepping \r\n dx=l/real(nx-1) !space stepping in x\r\n dy=h/real(ny-1) !space stepping in y\r\n print*,\"inter your total time = \"\r\n read*,ttime\r\n dt=ttime/real(nt-1)\r\n p=alpha*dt*((1/dx**2)+(1/dy**2))\r\n st=dt*nt\r\n \r\nWrite(*,*) 'please input your solver : 1 for explcit solver (FTCS) or 2 for alternative directional implcit (ADI)'\r\nRead(*,*) s\r\n \r\n allocate(u_old(nx,ny),u_new(nx,ny),upre(nx,ny),unow(nx,ny),ufut(nx,ny),X(nx,ny),Y(nx,ny))\r\n \r\n !grid generation \r\n\r\ndo i=1,nx\r\n do j=1,ny\r\n X(i,j)=(i-1)*dx\r\n Y(i,j)=(j-1)*dy\r\n end do\r\nend do\r\n\r\n \r\n \r\n! initial condition \r\n u_old(:,:)=50\r\n \r\n!boudary condition\r\nu_old(2:,ny)=(0.33333)*(4*u_old(ny-1,2:ny-1)-u_old(ny-2,2:ny-1)) !up\r\ndo j=1,ny\r\n u_old(1,j)=28*0.66*dx*(0-100)+(0.33333)*(4*u_old(2,j)-u_old(3,j)) !left\r\nend do \r\nu_old(nx,2:ny-1)=50 !right \r\nu_old(2:,1)=100 !down\r\n \r\n\r\nu_new=u_old\r\n\r\n!show initial and boudary condition \r\n Open(1,FIle='initial_condition.plt') \r\n Write(1,*) 'Variables=X,Y,unew'\r\n write(1,*)'zone I=',nx,'J=',ny\r\ndo J=1,ny\r\n Do I=1,nx\r\n Write(1,*) X(i,j),Y(i,j),u_old(i,j)\r\n END do \r\nend do \r\n\r\n\r\nif (s==1) then \r\n \r\n write(*,*) \"------------------------------------- FTCS--------------------------------------\"\r\n print*,'solving time is = ',st\r\n write(*,*)'this solver is based on stablity number, generally stablity number must be lower than 0.5'\r\n write(*,*)'CAUTION'\r\n write(*,*)'if your DELTA X= DELTA Y the stability number must be lower than 0.25'\r\n write(*,*)'your stablility number is = '\r\n write(*,*) p \r\n \r\n print*,\"please wait.....\" \r\n !FTCS_solver\r\n \r\n do t=1,nt \r\n do j=2,ny-1\r\n do i=2,nx-1\r\n \r\n u_new(i,j)=(alpha*dt/dx**2)*(u_old(i+1,j)-2*u_old(i,j)+u_old(i-1,j))+(Alpha*dt/dy**2)*(u_old(i,j+1)-2*u_old(i,j)+u_old(i,j-1))+u_old(i,j)\r\n \r\n \r\n end do\r\n end do \r\n \r\n !show result\r\n Open(2,FIle='FTCS_result.plt') \r\n Write(2,*) 'Variables=\"X\",\"Y\",\"unew\"'\r\n write(2,*)'zone I=',nx,'J=',ny\r\ndo J=1,ny\r\n Do I=1,nx\r\n Write(2,*) X(i,j),Y(i,j),u_new(i,j)\r\n END do \r\nend do \r\n\r\n u_old=u_new\r\n end do \r\nend if\r\n\r\n\r\n if (s==2) then \r\n \r\n \r\n \r\n write(*,*)\"------------------------------------- ADI--------------------------------------\"\r\n write(*,*)'this solver is stabled under any circumstances'\r\n \r\n \r\n u_old(:,:)=50\r\n \r\n\r\nu_old(2:,ny)=(0.33333)*(4*u_old(ny-1,2:ny-1)-u_old(ny-2,2:ny-1)) !up\r\ndo j=1,ny\r\n u_old(1,j)=28*0.66*dx*(0-100)+(0.33333)*(4*u_old(2,j)-u_old(3,j)) !left\r\nend do \r\nu_old(nx,2:ny-1)=50 !right ! \r\nu_old(2:,1)=100 !down\r\n\r\n\r\n unow(:,:)=50\r\n \r\nunow(2:,ny)=(0.33333)*(4*u_old(ny-1,2:ny-1)-u_old(ny-2,2:ny-1)) !up\r\ndo j=1,ny\r\n u_old(1,j)=28*0.66*dx*(0-100)+(0.33333)*(4*u_old(2,j)-u_old(3,j)) !left \r\nend do \r\nunow(nx,2:ny-1)=50 !right ! \r\nunow(2:,1)=100 !down\r\n\r\nufut=u_old\r\n\r\n print*,\"please wait.....\" \r\n do t=1,nt \r\n ! X sweep \r\n do i=2,nx-1\r\n do j=2,ny-1\r\n unow(i,j)=(alpha*dt/2)*((((unow(I+1,j)-2*unow(i,j)+unow(i-1,j))/dx**2))+(((u_old(i,j+1)-2*u_old(i,j)+u_old(i,j-1))/dy**2)))+u_old(i,j)\r\n \r\n end do \r\n end do \r\n \r\n !y sweep \r\n do i=2,nx-1\r\n do j=2,ny-1\r\n ufut(i,j)=(alpha*dt/2)*((((unow(i+1,j)-2*unow(I,J)+unow(i-1,j))/dx**2))+(((ufut(i,j+1)-2*ufut(i,j)+ufut(i,j-1))/dy**2)))+unow(i,j)\r\n \r\n end do \r\n end do \r\n \r\n \r\n ! show result \r\n Open(3,FIle='ADI_result.plt')\r\nWrite(3,*) 'Variables=X,Y,ufut'\r\nwrite(3,*)'zone I=',nx,'J=',ny\r\ndo J=1,ny\r\n Do I=1,nx\r\n Write(3,*) X(i,j),Y(i,j),ufut(i,j)\r\n END do \r\nend do \r\n u_old=unow\r\n unow=ufut\r\n\r\n end do \r\n end if \r\n \r\n print*,\"done!\"\r\npause\r\n\r\nend program heat_equation\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "80b66d098d1f4d8d5216e89a7f08199e615b9544", "size": 4810, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "heat2d2solvers.f90", "max_stars_repo_name": "mehrdadBHP1997/2D-heatEquation-FTCS-ADI", "max_stars_repo_head_hexsha": "c8e2a24afe1817268589cb0380687be7fa663d84", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "heat2d2solvers.f90", "max_issues_repo_name": "mehrdadBHP1997/2D-heatEquation-FTCS-ADI", "max_issues_repo_head_hexsha": "c8e2a24afe1817268589cb0380687be7fa663d84", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "heat2d2solvers.f90", "max_forks_repo_name": "mehrdadBHP1997/2D-heatEquation-FTCS-ADI", "max_forks_repo_head_hexsha": "c8e2a24afe1817268589cb0380687be7fa663d84", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 155, "alphanum_fraction": 0.4852390852, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436405, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8157591894958856}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c lagrange.f95\n! gfortran -o lagrange lagrange.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! ==============================================================================\n\nPROGRAM LAGRANGE_INTERPOLATION\n IMPLICIT NONE\n \n INTEGER :: I,K\n INTEGER,PARAMETER :: N=2\n REAL :: START, FINISH\n \n REAL :: L,P,XU\n REAL :: X(N),Y(N)\n \n \n ! READ DATA\n OPEN (1, FILE=\"data_lagrange.txt\")\n DO I = 1,N\n READ(1,*) X(I),Y(I)\n END DO\n CLOSE(1)\n \n CALL cpu_time(START)\n ! LAGRANGE PROCESS\n OPEN (2, FILE=\"LagrangeOut.txt\",STATUS=\"REPLACE\")\n XU = 10\n P = 0\n DO K = 1,N\n L = 1\n DO I = 1,N\n IF (I .ne. K) THEN\n L = L*((XU - X(I))/(X(K) - X(I)))\n END IF\n END DO\n P = P + (Y(K)*L)\n END DO\n WRITE(2,*) XU, P\n WRITE(*,*) XU, P\n CLOSE(1)\n CALL cpu_time(FINISH)\n \n WRITE(*,*)''\n WRITE(*,*)'NUMBER OF DATA:', N\n WRITE(*,*) 'TIME PROCESSING:',(FINISH-START),'SECONDS'\n \n END PROGRAM\n \n", "meta": {"hexsha": "105fac55b20c585059446ee9ebde67c1d6ee40b9", "size": 1213, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "lagrange.f95", "max_stars_repo_name": "auliakhalqillah/interpolation_lagrange", "max_stars_repo_head_hexsha": "4853daaa6c81772efa8b1eb15209026a9f0dd71c", "max_stars_repo_licenses": ["MIT"], "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.f95", "max_issues_repo_name": "auliakhalqillah/interpolation_lagrange", "max_issues_repo_head_hexsha": "4853daaa6c81772efa8b1eb15209026a9f0dd71c", "max_issues_repo_licenses": ["MIT"], "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.f95", "max_forks_repo_name": "auliakhalqillah/interpolation_lagrange", "max_forks_repo_head_hexsha": "4853daaa6c81772efa8b1eb15209026a9f0dd71c", "max_forks_repo_licenses": ["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.462962963, "max_line_length": 80, "alphanum_fraction": 0.5012366035, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172673767974, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.8157497735850111}} {"text": "SUBROUTINE ENU (rEF, rENU, eE, eN, eU)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: ENU.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Transformation from geocentric (XYZ) to local (East, North, Up) system \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - rEF:\t\t\tGeocentric Position vector \r\n!\r\n! Output arguments:\r\n! - rENU:\t\t\tVector in the local system East,North,Up (ENU) \r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 11 August 2016\r\n! ----------------------------------------------------------------------\r\n! Last modified\r\n! - Dr. Thomas Papanikolaou, 20 November 2018:\r\n!\tUpgraded from Fortran 90 to Fortran 2003 for calling the modified \r\n! subroutines (upgraded to F03) \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n !USE mdl_arr\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):: rEF(3)\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: rENU(3), eE(3), eN(3), eU(3)\r\n! ---------------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n\t REAL (KIND = prec_d), Dimension(3,3) :: Rx, Rz, R3\t \r\n\t REAL (KIND = prec_d) :: phi,lamda,radius\t \r\n\t REAL (KIND = prec_d) :: x_angle,z_angle\t \r\n INTEGER (KIND = prec_int2) :: AllocateStatus, DeAllocateStatus\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Spherical coordinates\r\nCALL coord_r2sph (rEF, phi,lamda,radius)\r\n\r\n! Rotation matrices\r\n x_angle = PI_global/2.D0 - phi\r\n Rx(1,1:3) = (/\t1.0D0,\t\t\t\t 0.0D0,\t\t 0.0D0 /)\r\n Rx(2,1:3) = (/\t0.0D0,\t\t\tcos(x_angle),\tsin(x_angle) /)\r\n Rx(3,1:3) = (/\t0.0D0,\t-1.D0 * sin(x_angle),\tcos(x_angle) /)\r\n\r\n z_angle = PI_global/2.D0 + lamda\r\n Rz(1,1:3) = (/ \t\t cos(z_angle), sin(z_angle), 0.0D0 /)\r\n Rz(2,1:3) = (/ -1.D0 * sin(z_angle), cos(z_angle), 0.0D0 /)\r\n Rz(3,1:3) = (/ \t\t0.0D0, 0.0D0, 1.0D0 /)\r\n\t \r\n! Allocate arrays for using matrix_RxR subroutine\r\n! ALLOCATE (R1(3,3), STAT = AllocateStatus)\r\n! ALLOCATE (R2(3,3), STAT = AllocateStatus)\r\n! ALLOCATE (R3(3,3), STAT = AllocateStatus)\r\n!\t R1 = Rx\r\n!\t R2 = Rz\r\n!\t CALL matrix_RxR\t \r\n \r\n! Coordinates in local East,North,Up (ENU) system\t \r\nR3 = MATMUL(Rx , Rz) \r\n CALL matrix_Rr (R3,rEF, rENU)\r\n\t \r\n\t \r\n! Unit vectors in local East,North,Up (ENU) system\t\r\n\t eE = (/ -sin(lamda)\t\t\t, cos(lamda)\t\t\t, 0.D0\t\t/)\r\n\t eN = (/ -cos(lamda)*sin(phi)\t, -sin(lamda)*sin(phi)\t, cos(phi)\t/)\r\n\t eU = (/ cos(lamda)*cos(phi)\t, sin(lamda)*cos(phi)\t, sin(phi)\t/)\r\n\r\n\r\n! Reverse East to West\r\n!eE = (/ sin(lamda)\t\t\t, -1.0D0 * cos(lamda)\t\t\t, 0.D0\t\t/)\r\n\r\n\r\nEND\r\n\r\n", "meta": {"hexsha": "30c185e6cb48e42135f08b7f9f86f74e82b4450b", "size": 3245, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/ENU.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/ENU.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/ENU.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.875, "max_line_length": 78, "alphanum_fraction": 0.4163328197, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.815749764891819}} {"text": "!> Fibonacci numbers module.\n\n!! Copyright 2014 The University of Edinburgh.\n!!\n!! Licensed under the Apache License, Version 2.0 (the \"License\"); \n!! you may not use this file except in compliance with the License. \n!! You may obtain a copy of the License at\n!!\n!! http://www.apache.org/licenses/LICENSE-2.0\n!!\n!! Unless required by applicable law or agreed to in writing, software \n!! distributed under the License is distributed on an \"AS IS\" BASIS, \n!! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n!! implied. See the License for the specific language governing\n!! permissions and limitations under the License.\n\nmodule fibonacci_module\n\n implicit none\n\ncontains\n\n !> Calculate the Fibonacci number of the given integer.\n recursive function fibonacci(n) result (fib)\n integer, intent(in) :: n !< If n <= 0 then 0 is assumed.\n integer :: fib !< Fibonacci number\n if (n < 2) then\n fib = n\n else\n fib = fibonacci(n - 1) + fibonacci(n - 2)\n endif\n end function fibonacci\n\nend module fibonacci_module\n", "meta": {"hexsha": "573d2fd1a44d799388ee51c3d071b20da5ad9596", "size": 1064, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/fibonacci.f90", "max_stars_repo_name": "abegomez/build_and_test_examples", "max_stars_repo_head_hexsha": "93ceaf4e9f96ef5673a5a5358a91fffdbfd58904", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 114, "max_stars_repo_stars_event_min_datetime": "2015-11-06T10:16:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T23:04:56.000Z", "max_issues_repo_path": "fortran/src/fibonacci.f90", "max_issues_repo_name": "abegomez/build_and_test_examples", "max_issues_repo_head_hexsha": "93ceaf4e9f96ef5673a5a5358a91fffdbfd58904", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2017-10-23T15:07:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-01T06:40:50.000Z", "max_forks_repo_path": "fortran/src/fibonacci.f90", "max_forks_repo_name": "abegomez/build_and_test_examples", "max_forks_repo_head_hexsha": "93ceaf4e9f96ef5673a5a5358a91fffdbfd58904", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 212, "max_forks_repo_forks_event_min_datetime": "2015-05-14T08:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-16T13:43:10.000Z", "avg_line_length": 30.4, "max_line_length": 71, "alphanum_fraction": 0.7020676692, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.8155623673293845}} {"text": "! Written by Rand Huso\n\n! here's an example ( after the fact ): http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap06/trigon.html\nMODULE LMathMod\n USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : real32, real64\n IMPLICIT NONE\n PRIVATE\n REAL( KIND=real64 ), PARAMETER, PUBLIC :: LMathPI = 4*ATAN( 1.E0_real64 )\n REAL( KIND=real64 ), PARAMETER, PUBLIC :: LMathPI2 = LMathPI/2\n REAL( KIND=real64 ), PARAMETER, PUBLIC :: LMathDegToRad = LMathPI / 180._real64\n REAL( KIND=real32 ), PARAMETER, PUBLIC :: LMathPI32 = 4*ATAN( 1.E0_real32 )\n REAL( KIND=real32 ), PARAMETER, PUBLIC :: LMathDegToRad32 = LMathPI32 / 180._real32\n\n INTERFACE toRadians\n MODULE PROCEDURE toRadians32, toRadians64\n END INTERFACE\n\n INTERFACE toDegrees\n MODULE PROCEDURE toDegrees32, toDegrees64\n END INTERFACE\n\n PUBLIC SIND\n INTERFACE SIND\n MODULE PROCEDURE SIND32, SIND64\n END INTERFACE\n\n PUBLIC COSD\n INTERFACE COSD\n MODULE PROCEDURE COSD32, COSD64\n END INTERFACE\n\n PUBLIC TAND\n INTERFACE TAND\n MODULE PROCEDURE TAND32, TAND64\n END INTERFACE\n\n PUBLIC ATAND\n INTERFACE ATAND\n MODULE PROCEDURE ATAND32, ATAND64\n END INTERFACE\n\nCONTAINS\n\n ELEMENTAL REAL( KIND=real64 ) FUNCTION toRadians64( degrees ) ! ELEMENTAL implies PURE\n REAL( KIND=real64 ), INTENT( in ) :: degrees\n toRadians64 = degrees * LMathDegToRad\n END FUNCTION\n\n ELEMENTAL REAL( KIND=real32 ) FUNCTION toRadians32( degrees )\n REAL( KIND=real32 ), INTENT( in ) :: degrees\n toRadians32 = degrees * LMathDegToRad32\n END FUNCTION\n\n ELEMENTAL REAL( KIND=real64 ) FUNCTION toDegrees64( radians )\n REAL( KIND=real64 ), INTENT( in ) :: radians\n toDegrees64 = radians / LMathDegToRad\n END FUNCTION\n\n ELEMENTAL REAL( KIND=real32 ) FUNCTION toDegrees32( radians )\n REAL( KIND=real32 ), INTENT( in ) :: radians\n toDegrees32 = radians / LMathDegToRad32\n END FUNCTION\n\n ELEMENTAL REAL( KIND=real64 ) FUNCTION SIND64( degrees )\n IMPLICIT NONE\n REAL( KIND=real64 ), INTENT( in ) :: degrees\n SIND64 = sin( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real32 ) FUNCTION SIND32( degrees )\n IMPLICIT NONE\n REAL( KIND=real32 ), INTENT( in ) :: degrees\n SIND32 = sin( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real64 ) FUNCTION COSD64( degrees )\n IMPLICIT NONE\n REAL( KIND=real64 ), INTENT( in ) :: degrees\n COSD64 = cos( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real32 ) FUNCTION COSD32( degrees )\n IMPLICIT NONE\n REAL( KIND=real32 ), INTENT( in ) :: degrees\n COSD32 = cos( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real64 ) FUNCTION TAND64( degrees )\n IMPLICIT NONE\n REAL( KIND=real64 ), INTENT( in ) :: degrees\n TAND64 = tan( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real32 ) FUNCTION TAND32( degrees )\n IMPLICIT NONE\n REAL( KIND=real32 ), INTENT( in ) :: degrees\n TAND32 = tan( toRadians( degrees ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real64 ) FUNCTION ATAND64( value )\n IMPLICIT NONE\n REAL( KIND=real64 ), INTENT( in ) :: value\n ATAND64 = toDegrees( atan( value ) )\n END FUNCTION\n!\n ELEMENTAL REAL( KIND=real32 ) FUNCTION ATAND32( value )\n IMPLICIT NONE\n REAL( KIND=real32 ), INTENT( in ) :: value\n ATAND32 = toDegrees( atan( value ) )\n END FUNCTION\nEND MODULE\n!---------!---------!---------!---------!---------!---------!---------!---------!---------!---------!---------!---------!---------!-\n", "meta": {"hexsha": "f83fc9cfe6c403c61a600a10b40673fa94dff7c5", "size": 3710, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/libHdf5/LMathMod.f90", "max_stars_repo_name": "rchuso/Mpi-IoC-HDF5-Fortran-CMake", "max_stars_repo_head_hexsha": "e631a1efc2b0424db8a72036df711bb749ba207a", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2019-06-09T17:56:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-12T22:46:26.000Z", "max_issues_repo_path": "code/libHdf5/LMathMod.f90", "max_issues_repo_name": "rchuso/Mpi-IoC-HDF5-Fortran-CMake", "max_issues_repo_head_hexsha": "e631a1efc2b0424db8a72036df711bb749ba207a", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-11T03:37:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-11T03:37:04.000Z", "max_forks_repo_path": "code/libHdf5/LMathMod.f90", "max_forks_repo_name": "rchuso/Mpi-IoC-HDF5-Fortran-CMake", "max_forks_repo_head_hexsha": "e631a1efc2b0424db8a72036df711bb749ba207a", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-06-11T02:24:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-15T09:46:41.000Z", "avg_line_length": 32.8318584071, "max_line_length": 132, "alphanum_fraction": 0.623180593, "num_tokens": 1056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198241, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.8155292041914897}} {"text": "!!# FUNCTION MODULE: <>\nMODULE FUN_CellGradient_Gauss\n\n!!## PURPOSE\n!! Compute a gradient in a cell according to Gauss' Theorem:\n!!\n!! $$ \\vec{\\nabla} f = \\lim_{V \\rightarrow 0} \\frac{1}{V}\n!! \\int_{A} f d\\vec{A} $$\n!!\n!! where $V$ is the volume and the integral over $A$ implies an\n!! integral over the surface of the cell.\n\n\n!!## DETAILS\n!! In discrete form, for a cell composed of planar faces we have:\n!!\n!! $$ \\vec{\\nabla} f_c = \\frac{1}{V_c} \\sum_\\alpha \\vec{A}_\\alpha f_\\alpha $$,\n!!\n!! where $\\vec{\\nabla}f_c$ is the gradient at the centroid of the cell,\n!! $V_c$ is the volume of the cell, $\\vec{A}_\\alpha$ are the area vectors\n!! of each face $\\alpha$, and $f_\\alpha$ are the function values at the centroids\n!! of the faces.\n\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## DEFAULT ACCESS\nPRIVATE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE CellGradient_Gauss\n MODULE PROCEDURE CellGradient_Gauss_Rsp\n MODULE PROCEDURE CellGradient_Gauss_Rdp\nEND INTERFACE\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: CellGradient_Gauss_Rsp\nPUBLIC :: CellGradient_Gauss_Rdp\nPUBLIC :: CellGradient_Gauss\n\n\n!!## MODULE PROCEDURES\nCONTAINS\n\n!!### PURE FUNCTION <>\nPURE FUNCTION CellGradient_Gauss_Rsp( Nd , Na , Vc , A , Fa ) RESULT(CellGradient)\n\n!!#### LOCAL PARAMETERS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"03-A-FUN_CellGradient_Gauss.f90.hdr\"\n!!--begin--\nINCLUDE \"03-A-FUN_CellGradient_Gauss.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n!!### PURE FUNCTION <>\nPURE FUNCTION CellGradient_Gauss_Rdp( Nd , Na , Vc , A , Fa ) RESULT(CellGradient)\n\n!!#### LOCAL PARAMETERS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"03-A-FUN_CellGradient_Gauss.f90.hdr\"\n!!--begin--\nINCLUDE \"03-A-FUN_CellGradient_Gauss.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "0771c4caae74aa9f7e26dd8c3668585479b528fd", "size": 1893, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/03-A-FUN_CellGradient_Gauss.f90", "max_stars_repo_name": "wawiesel/tapack", "max_stars_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/03-A-FUN_CellGradient_Gauss.f90", "max_issues_repo_name": "wawiesel/tapack", "max_issues_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/03-A-FUN_CellGradient_Gauss.f90", "max_forks_repo_name": "wawiesel/tapack", "max_forks_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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.9315068493, "max_line_length": 82, "alphanum_fraction": 0.7115689382, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936262, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.8155292023649573}} {"text": "program Fresnel_test\n implicit none\n real x,cx,sx,h\n integer i,n \n n=1000\n h=0.01\n do i =-n,n \n x=h*i \n call fresnel(x,cx,sx)\n print *,x,\",\",cx,\",\",sx\n enddo\nend program Fresnel_test\n\nsubroutine fresnel(x,cx,sx)\n implicit none\n real, parameter :: pi=3.14159265358979,pi2=(pi/2)**2\n real, parameter :: eps = 1e-15 \n real x,cx,sx,xa,x2,x4,f,g,xp \n integer k,kmax,k2,k4 \n complex z,zcs,zcs1,zc0,zd0,zc1,zd1,zc2,zd2,zbi \n if(x==0) then \n cx=0; sx=0\n return \n endif \n xa=abs(x)\n if(xa<2) then \n kmax=100 \n x2=xa*xa \n f=xa \n g=pi*xa*x2/2\n x4=x2*x2\n cx=f\n sx=g/3\n do k=1,kmax\n k2=k+k\n k4=k2+k2\n f=-f*pi2*x4/(k2*(k2-1))\n cx=cx+f/(k4+1)\n g=-g*pi2*x4/((k2+1)*k2) \n sx=sx+g/(k4+3)\n if(abs(f) 0) then\n advection2dx(i, j) = vx(i, j) * (T(i, j) - T(i-1, j)) / hx\n else\n advection2dx(i, j) = vx(i, j) * (T(i+1, j) - T(i, j)) / hx\n end if\n end do\n\n end function advection2dx\n\n function advection2dy(T, hy, vy)\n implicit none\n ! arguments\n real, intent(in) :: hy\n real, intent(in) :: T(:, :)\n real, intent(in) :: vy(:, :)\n ! result\n real, dimension(size(T, 1), size(T, 2)) :: advection2dy\n ! local variables\n integer :: i, j\n integer :: nx, ny\n nx = size(T, 1)\n ny = size(T, 2)\n\n do concurrent (i=2:nx-1, j=2:ny-1)\n if (vy(i, j) > 0) then\n advection2dy(i, j) = vy(i, j) * (T(i, j) - T(i, j-1)) / hy\n else\n advection2dy(i, j) = vy(i, j) * (T(i, j+1) - T(i, j)) / hy\n end if\n end do\n\n end function advection2dy\n\nend module m_fdm\n", "meta": {"hexsha": "fb9de5afa4380830fbe2f8e9c6b99587eb6bb522", "size": 1935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "m_fdm.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_fdm.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_fdm.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": 25.8, "max_line_length": 72, "alphanum_fraction": 0.4764857881, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152282, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8150940868712501}} {"text": "module quadratures\n !-----------------------------------------------------------------------------\n ! Module: quadratures\n ! This modules contains subroutines for computing and testing numerical\n ! quadratures.\n !\n ! Subroutines:\n ! gausslegendre (public)\n ! Compute the Gauss-Legendre quadrature of degree N using the Golub-Welsh\n ! algorithm.\n !\n ! gausslegendre_shifted (public)\n ! Compute the Gauss-Legendre quadrature of degree N using the Golub-Welsh\n ! algorithm and map to the interval (0, 1).\n !\n ! gausslegendre_truncated (public)\n ! Compute the Gauss-Legendre quadrature of degree 2N using the Golub-Welsh\n ! algorithm and truncate returning only the positive gridpoints.\n !\n ! polytest (public)\n ! Test an integral quadrature against the analytic solution of an integral\n ! of the form integral[a,b] x^{m} dx\n !\n ! Useful Citations:\n ! Golub, Gene H., and John H. Welsch. \"Calculation of Gauss\n ! quadrature rules.\" Mathematics of computation (1969): 221-230.\n !---\n ! Developed by J.P. Dark\n ! Contact: email@jpdark.com\n ! Last modified June 2017\n !-----------------------------------------------------------------------------\n\n\n implicit none\n\n integer, parameter :: sp = kind(1.0)\n integer, parameter :: dp = kind(1.d0)\n real(dp), parameter :: PI = 3.141592653589793_dp\n\n\n private\n public :: gausslegendre, gausslegendre_truncated, gausslegendre_shifted, &\n clencurt, polytest\n\ncontains\n\n subroutine gausslegendre(N, mu, wt)\n !!------------------------------------------------------------------------\n !! Name: gausslegendre\n !! Compute the Gauss-Legendre quadrature of degree N using the\n !! Golub-Welsh algorithm.\n !!\n !! Synopsis\n !! subroutine gausslegendre(N, mu, wt)\n !!\n !! INPUT\n !! Integer ------------- N\n !!\n !! OUTPUT\n !! Double precision ---- mu(N), wt(N)\n !!\n !! Purpose\n !! Compute the Nth order Gauss-Legendre with quadrature points mu and\n !! the associated weigths wt on the interval (-1, 1).\n !!\n !! Citation:\n !! Golub, Gene H., and John H. Welsch. \"Calculation of Gauss\n !! quadrature rules.\" Mathematics of computation (1969): 221-230.\n !!\n !!\n !! Arguments N (input) integer The number of quadrature points.\n !!\n !! mu (output) double precision, array(N)\n !! Quadrature points.\n !!\n !! wt (output) double precision, array(N)\n !! Associated weights.\n !!------------------------------------------------------------------------\n implicit none\n integer(8), intent(in) :: N\n real(dp), intent(out), dimension(N) :: mu, wt\n real(dp) :: z(N, N)\n real(dp) :: e(N-1)\n real(dp) :: work(N-1, N-1)\n real(dp) :: tmp\n integer(8) :: info\n integer(8) :: mm\n if (mod(N, 2) /= 0) then\n write(*, *) &\n '> WARNING: Quadrature contains the origin.'\n endif\n mu = 0.0_dp\n do mm = 1, N-1\n tmp = 1.0_dp / (2.0_dp * real(mm, dp)) ** 2\n e(mm) = 0.5_dp / dsqrt(1.0_dp - tmp)\n enddo\n call dsteqr('I', N, mu, e, z, N, work, info)\n do mm = 1, N\n wt(mm) = 2.0_dp * z(1, mm) ** 2\n enddo\n end subroutine gausslegendre\n\n\n subroutine gausslegendre_shifted(N, mu, wt)\n !!------------------------------------------------------------------------\n !! Name: gausslegendre_shifted\n !! Compute the Gauss-Legendre quadrature of degree N using the\n !! Golub-Welsh algorithm and map to the interval (0, 1)\n !!\n !! Synopsis\n !! subroutine gausslegendre(N, mu, wt)\n !!\n !! INPUT\n !! Integer ------------- N\n !!\n !! OUTPUT\n !! Double precision ---- mu(N), wt(N)\n !!\n !! Purpose\n !! Compute the Nth order Gauss-Legendre with quadrature points mu and\n !! the associated weigths wt on the interval (-1, 1) and shift using\n !! linear transform\n !!\n !! mu --> 0.5 * (mu + 1)\n !!\n !! into the interval (0, 1).\n !!\n !! Citation:\n !! Golub, Gene H., and John H. Welsch. \"Calculation of Gauss\n !! quadrature rules.\" Mathematics of computation (1969): 221-230.\n !!\n !!\n !! Arguments\n !! N (input) integer\n !! The number of quadrature points.\n !!\n !! mu (output) double precision, array(N)\n !! Quadrature points.\n !!\n !! wt (output) double precision, array(N)\n !! Associated weights.\n !!------------------------------------------------------------------------\n implicit none\n integer(8), intent(in) :: N\n real(dp), intent(out) :: mu(N), wt(N)\n real(dp) :: z(N, N)\n real(dp) :: e(N-1)\n real(dp) :: work(N-1, N-1)\n real(dp) :: tmp\n integer(8) :: info\n integer(8) :: mm\n mu = 0.0_dp\n do mm = 1, N-1\n tmp = 1.0_dp / (2.0_dp * real(mm, dp)) ** 2\n e(mm) = 0.5_dp / dsqrt(1.0_dp - tmp)\n enddo\n call dsteqr('I', N, mu, e, z, N, work, info)\n mu = 0.5_dp * (mu + 1.0_dp)\n do mm = 1, N\n wt(mm) = z(1, mm) ** 2\n enddo\n end subroutine gausslegendre_shifted\n\n\n subroutine gausslegendre_truncated(N, mu, wt)\n !!--------------------------------------------------------------------------\n !! Name: gausslegendre_truncated\n !! Compute the Gauss-Legendre quadrature of degree 2N using the\n !! Golub-Welsh algorithm and truncate returning the positive gridpoints.\n !!\n !! Synopsis\n !! subroutine gausslegendre(N, mu, wt)\n !!\n !! INPUT\n !! Integer ------------- N\n !!\n !! OUTPUT\n !! Double precision ---- mu(N), wt(N)\n !!\n !! Purpose\n !! Compute the (2*N)th order Gauss-Legendre with quadrature points mu and\n !! the associated weigths wt on the interval (-1, 1) and return the N\n !! gridpoints and associated weights on the interval (0, 1).\n !!\n !! Citation:\n !! Golub, Gene H., and John H. Welsch. \"Calculation of Gauss\n !! quadrature rules.\" Mathematics of computation (1969): 221-230.\n !!\n !!\n !! Arguments\n !! N (input) integer\n !! The number of quadrature points.\n !!\n !! mu (output) double precision, array(N)\n !! Quadrature points.\n !!\n !! wt (output) double precision, array(N)\n !! Associated weights.\n !!---------------------------------------------------------------------------\n implicit none\n integer(8), intent(in) :: N\n real(dp), dimension(N) :: mu, wt\n real(dp), dimension(2*N) :: x\n real(dp) :: z(2*N, 2*N)\n real(dp) :: e(2*N-1)\n real(dp) :: work(2*N-1, 2*N-1)\n real(dp) :: tmp\n integer(8) :: info\n integer(8) :: mm\n x = 0.0_dp\n do mm = 1, 2*N-1\n tmp = 1.0_dp / (2.0_dp * real(mm, dp)) ** 2\n e(mm) = 0.5_dp / dsqrt(1.0_dp - tmp)\n enddo\n call dsteqr('I', 2*N, x, e, z, 2*N, work, info)\n mu = x(N+1:2*N)\n do mm = 1, N\n wt(mm) = 2.0_dp * z(1, N + mm) ** 2\n enddo\n end subroutine gausslegendre_truncated\n\n\n subroutine clencurt(N, mu, wt)\n !!--------------------------------------------------------------------------\n !! Name: gausslegendre_truncated\n !! Compute the Clenshaw-Curtis quadrature of degree N for even N.\n !!\n !! Synopsis\n !! subroutine clencurt(N, mu, wt)\n !!\n !! INPUT\n !! Integer ------------- N\n !!\n !! OUTPUT\n !! Double precision ---- mu(N), wt(N)\n !!\n !! Purpose\n !! Compute the Clenshaw-Curtis quadrature on the interval [-1, 1].\n !!\n !! *Method adapted from Matlab function in book:\n !! Spectral Methods in MATLAB by Lloyd N. Trefethen (p.128).\n !!\n !! Arguments\n !! N (input) integer\n !! The number of quadrature points (even).\n !!\n !! mu (output) double precision, array(N)\n !! Quadrature points.\n !!\n !! wt (output) double precision, array(N)\n !! Associated weights.\n !!---------------------------------------------------------------------------\n implicit none\n integer(8), intent(in) :: N\n real(dp), intent(out), dimension(N) :: mu, wt\n real(dp), dimension(N) :: theta\n integer(8) :: M\n real(dp) :: tmp1\n integer(8) :: ii, jj\n\n !---------------------------------------------------------------------------\n ! Chebyshev gridpoints mu = cos(theta) where theta[n] = pi * (n-1) / N.\n !\n theta(1) = 0.0_dp\n tmp1 = PI / real(N-1, dp)\n do ii = 1, N-1\n theta(ii+1) = tmp1 * real(ii, dp)\n enddo\n mu = cos(theta)\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! Compute weight\n !\n M = N-1\n if (mod(N, 2) .eq. 0) then\n wt(1) = 1.0_dp / real((N-1) ** 2, dp)\n wt(N) = wt(1)\n wt(2:M) = 1.0_dp\n do jj = 1, N/2-1\n ! wt -= 2 * cos(2 * j * theta) / (4 * j^2 - 1)\n tmp1 = real(2 * jj ** 2, dp) - 0.5_dp\n wt(2:M) = wt(2:M) - cos(2.0_dp * real(jj, dp) * theta(2:M)) &\n / tmp1\n enddo\n ! wt *= 2 / (M)\n wt(2:M) = wt(2:M) / (real(N/2, dp) - 0.5_dp)\n else\n write(*, '(A)') '> Warning in __quadratures_MOD_clencurt'\n write(*, '(A)') &\n '> Warning: Odd number of quadrature points - origin is included.'\n\n wt(1) = 1.0_dp / real(M ** 2 - 1, dp)\n wt(N) = wt(1)\n wt(2:M) = 1.0_dp\n do jj = 1, M/2 - 1\n ! wt -= 2 * cos(2 * j * theta) / (4 * j^2 - 1)\n tmp1 = real(2 * jj ** 2, dp) - 0.5_dp\n wt(2:M) = wt(2:M) - cos(2.0_dp * real(jj, dp) * theta(2:M)) &\n / tmp1\n enddo\n ! wt -= cos((M) * theta) / ((M)^2 - 1)\n wt(2:M) = wt(2:M) - cos(real(M, dp) * theta(2:M)) &\n / real(M ** 2 - 1, dp)\n ! wt *= 2 / (M)\n wt(2:M) = wt(2:M) / real(M/2, dp)\n endif\n\n\n end subroutine clencurt\n\n\n\n\n subroutine polytest(N, m, a, b, x, wt)\n !!--------------------------------------------------------------------------\n !! Name: polytest\n !! Test an integral quadrature against the analytic solution of an integral\n !! of the form integral[a,b] x^{m} dx\n !!\n !!\n !! Synopsis\n !! subroutine polytest( N, M, a, b, x, wt )\n !!\n !! Integer ------------- N, M\n !! Double precision ---- a, b, x( N ), wt( N )\n !!\n !! Purpose\n !! Compute the integral\n !!\n !! I = Integral_{a}^{b} x^{M} dx\n !!\n !! both analytically,\n !!\n !! I_true = 1/(M+1) (b^{M+1} - a^{M+1}),\n !!\n !! and with the quadrature,\n !!\n !! I_quad = sum[n=1,N] x(n)^m * wt(n).\n !!\n !! Compare the results to verify the correctness of the quadrature.\n !!\n !! Arguments\n !! N (input) integer\n !! The number of quadrature points.\n !!\n !! M (input) integer\n !! Order of the polynomial in integral.\n !!\n !! a (output) double precision, array(N)\n !! Start point of the interval the quadrature is defined on.\n !!\n !! b (output) double precision, array(N)\n !! End point of the interval the quadrature is defined on.\n !!\n !! x (output) double precision, array(N)\n !! Quadrature points.\n !!\n !! wt (output) double precision, array(N)\n !! Associated weights.\n !!---------------------------------------------------------------------------\n implicit none\n ! Input\n integer(8), intent(in) :: N\n integer, intent(in) :: M\n real(dp), intent(in) :: a, b\n real(dp), intent(in), dimension(N) :: x, wt\n ! Workspace\n real(dp) :: approximate, analytic\n if (M .eq. -1) then\n analytic = log(b) - log(a)\n else\n analytic = (b ** (M+1) - a ** (M+1)) / real(M+1, dp)\n endif\n approximate = sum(x ** M * wt)\n write(*, '(A, F4.1, A, F4.1, A, I4)') &\n '> Integrate x^m from b to a where: a = ', a, ', b = ', b, &\n ', m = ', M\n write(*, '(A, F8.6,A, F8.6, A, E12.4)') 'Analytic = ', analytic, &\n '; Numeric = ', approximate, '; Error = ', analytic - approximate\n write(*,*) \"\"\n end subroutine polytest\n\nend module quadratures\n", "meta": {"hexsha": "52bfbcc1c1dd71c988c974e14b2e4cf7c931879d", "size": 12016, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "quadratures.f95", "max_stars_repo_name": "ugks/pddom", "max_stars_repo_head_hexsha": "d02e2ff3d10d6e7b49295ef60183f8b76633e319", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-20T00:09:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-20T00:09:56.000Z", "max_issues_repo_path": "quadratures.f95", "max_issues_repo_name": "ugks/pddom", "max_issues_repo_head_hexsha": "d02e2ff3d10d6e7b49295ef60183f8b76633e319", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "quadratures.f95", "max_forks_repo_name": "ugks/pddom", "max_forks_repo_head_hexsha": "d02e2ff3d10d6e7b49295ef60183f8b76633e319", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-01-18T15:16:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:09:57.000Z", "avg_line_length": 31.2103896104, "max_line_length": 81, "alphanum_fraction": 0.4826065246, "num_tokens": 3642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.8149384760373057}} {"text": "MODULE Matrix\n\n ! #DES: Module containing routines for manipulating matrices, focused on explicit solutions\n ! for 2- and 3-dimensional matrices. \n\n IMPLICIT NONE\n\nCONTAINS\n\n FUNCTION Eigenvalues2DRealSymmetric(A)\n\n ! #DES: Explicit solution for eigenvalues of a 2D real, symmetric matrix\n ! #DES: Obtained by solving the appropriate secular equation, det(A - lI) = 0, (a quadratic with 2 real roots)\n\n IMPLICIT NONE\n REAL(8), INTENT(IN) :: A(2,2)\n REAL(8) :: eigenvalues2DRealSymmetric(2)\n REAL(8) :: sum, diff, sqrtD !discriminant\n\n IF (A(1,2) /= A(2,1)) STOP \"Error: Matrix - nonsymmetric matrix passed to Eigenvalues2DRealSymmetric\"\n\n IF (A(1,2) == 0.0d0) THEN\n\n !trivial solution - matrix is already diagonal\n eigenvalues2DRealSymmetric(1) = A(1,1)\n eigenvalues2DRealSymmetric(2) = A(2,2)\n\n ELSE\n\n sum = A(1,1) + A(2,2)\n diff = A(1,1) - A(2,2)\n sqrtD = SQRT(diff*diff + 4.0d0*A(1,2)*A(1,2))\n\n eigenvalues2DRealSymmetric(1) = 0.5d0 * (sum + sqrtD)\n eigenvalues2DRealSymmetric(2) = 0.5d0 * (sum - sqrtD)\n\n ENDIF\n\n END FUNCTION Eigenvalues2DRealSymmetric\n\n!*\n\n FUNCTION Eigenvalues3DRealSymmetric(A)\n\n !https://gitlab.dune-project.org/lars.lubkoll/dune-common/commit/3e91e19881ec7a8708ba2dab17d7f8694ddb7e08\n !https://en.wikipedia.org/wiki/Eigenvalue_algorithm#Direct_calculation\n\n IMPLICIT NONE\n REAL(8), INTENT(IN) :: A(3,3)\n REAL(8) :: eigenvalues3DRealSymmetric(3)\n REAL(8), PARAMETER :: pi = 3.14159d0\n REAL(8) :: p, p1, q, p2, r, phi, diff\n REAL(8) :: I(3,3), B(3,3)\n INTEGER :: j\n\n p1 = A(1,2)*A(1,2) + A(1,3)*A(1,3) + A(2,3)*A(2,3)\n\n IF (p1 == 0.0d0) THEN\n\n !A is already diagonal so return its diagonal entries\n DO j = 1, 3\n eigenvalues3DRealSymmetric(j) = A(j,j)\n ENDDO\n\n ELSE\n\n I(:,:) = 0.0d0\n DO j = 1, 3\n I(j,j) = 1.0d0\n ENDDO\n\n q = trace(A) / 3.0d0\n p2 = 2.0d0 * p1\n DO j = 1, 3\n diff = A(j,j) - q\n p2 = p2 + (diff*diff)\n ENDDO\n p = SQRT(p2 / 6.0d0)\n\n B(:,:) = (1.0d0 / p) * (A(:,:) - q * I(:,:)) ! I is the identity matrix\n\n r = determinant(B) / 2.0d0\n\n ! In exact arithmetic for a symmetric matrix -1 <= r <= 1\n ! but computation error can leave it slightly outside this range.\n IF (r <= -1.0d0) THEN\n phi = pi / 3.0d0\n ELSEIF (r >= 1.0d0) THEN\n phi = 0.0d0\n ELSE\n phi = acos(r) / 3.0d0\n END IF\n\n ! the eigenvalues satisfy eig3 <= eig2 <= eig1\n eigenvalues3DrealSymmetric(1) = q + (2 * p * COS(phi))\n eigenvalues3DRealSymmetric(3) = q + (2 * p * COS(phi + (2*pi/3)))\n ! since trace(A) = eig1 + eig2 + eig3\n eigenvalues3DRealSymmetric(2) = (3.0d0 * q) - eigenvalues3DRealSymmetric(1) - eigenvalues3DRealSymmetric(3)\n\n END IF\n\n END FUNCTION Eigenvalues3DRealSymmetric\n\n!*\n\n REAL(8) FUNCTION determinant(A)\n\n IMPLICIT NONE\n REAL(8), INTENT(IN) :: A(3,3)\n\n determinant = 0.0d0\n determinant = determinant + (A(1,1) * (A(2,2)*A(3,3) - A(2,3)*A(3,2)))\n determinant = determinant + (A(1,2) * (A(2,1)*A(3,3) - A(2,3)*A(3,1)))\n determinant = determinant + (A(1,3) * (A(2,1)*A(3,2) - A(2,2)*A(3,1)))\n\n END FUNCTION determinant\n\n!*\n\n REAL(8) FUNCTION trace(A)\n\n ! #DES: Compute trace of an n-by-n square matrix, the sum of the elements on the main diagonal\n\n IMPLICIT NONE\n REAL(8), INTENT(IN) :: A(:,:)\n INTEGER :: i\n\n IF (SIZE(A,1) /= SIZE(A,2)) STOP \"Error: Matrix - non-square matrix received as input to trace\"\n\n trace = 0.0d0\n DO i = 1, SIZE(A,1)\n trace = trace + A(i,i)\n ENDDO\n\n END FUNCTION trace\n\nEND MODULE Matrix\n", "meta": {"hexsha": "2245f7764d79cb78258371617693fb1bdc195018", "size": 3674, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Matrix.f90", "max_stars_repo_name": "MJLMills/fepcat", "max_stars_repo_head_hexsha": "ffebd0c590219da1dbc5662c840cc42bcf7ab593", "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": "Matrix.f90", "max_issues_repo_name": "MJLMills/fepcat", "max_issues_repo_head_hexsha": "ffebd0c590219da1dbc5662c840cc42bcf7ab593", "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": "Matrix.f90", "max_forks_repo_name": "MJLMills/fepcat", "max_forks_repo_head_hexsha": "ffebd0c590219da1dbc5662c840cc42bcf7ab593", "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": 26.6231884058, "max_line_length": 114, "alphanum_fraction": 0.5944474687, "num_tokens": 1377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8774768002981829, "lm_q1q2_score": 0.8146571819419284}} {"text": "module maths_module\n\n use iso_fortran_env, wp => real64\n implicit none\n\n real (wp), parameter :: c = 299792458.0_wp\n real (wp), parameter :: e = &\n 2.7182818284590452353602874713526624977_wp\n real (wp), parameter :: g = 9.812420_wp\n real (wp), parameter :: pi = &\n 3.141592653589793238462643383279502884_wp\nend module\n\nmodule sub1_module\n\ncontains\n subroutine sub1(radius, area, circumference)\n use iso_fortran_env, wp => real64\n use maths_module\n implicit none\n\n real(wp), intent(in) :: radius\n real(wp), intent(out) :: area, circumference\n\n area = pi*radius*radius\n circumference = 2._wp*pi*radius\n end subroutine\nend module\n\nprogram ch2101\n ! Modules for Precision Specification and\n ! Constant Definition\n use iso_fortran_env, wp => real64\n use sub1_module\n implicit none\n\n real(wp) :: r, a, c\n\n print *, 'radius?'\n read *, r\n call sub1(r,a,c)\n print *, ' for radius = ', r\n print *, ' area = ', a\n print *, ' circumference = ', c\nend program\n", "meta": {"hexsha": "066739712222e8dadb9e3668af797bc41179f659", "size": 1070, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch21/ch2101.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": "ch21/ch2101.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": "ch21/ch2101.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": 23.2608695652, "max_line_length": 52, "alphanum_fraction": 0.6299065421, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632302488964, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8146532426140679}} {"text": "function fourierWaveNum(n,Lx) result(ks)\n! Returns fourier wavenumbers for n modes on domain of size Lx\n! === Parameters ===\n! n - (real) number of modes\n! Lx - (real) domain size\n! === Output ===\n! ks - (array) array of wavenumbers\ninteger, intent(in) :: n\nreal(kind=8), intent(in) :: Lx\nreal(kind=8), allocatable :: ks(:)\ninteger :: i\nreal(kind=8) :: s\nallocate(ks(n))\ns = (2.d0*PI)/Lx; ! Fourier wave number scaling factor\ndo i=0,n-1\n if (i <= n/2) then\n ks(i+1) = s*i\n else\n ks(i+1) = s*(-n + i)\n end if\nenddo\n\nend function fourierWaveNum", "meta": {"hexsha": "68dd2ef603db3300dd0e8035d80b1458c4b5fd82", "size": 578, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/fourierwavnum.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/fourierwavnum.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/fourierwavnum.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": 25.1304347826, "max_line_length": 62, "alphanum_fraction": 0.6038062284, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951863228883365, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.8146532396955133}} {"text": "\n\nPROGRAM standard_deviation\n IMPLICIT NONE\n REAL (KIND = 4) :: sum, sumsq2, xbar\n REAL (KIND = 4) :: sigma1, sigma2\n REAL (KIND = 4), DIMENSION (127) :: x\n INTEGER :: i\n\n x=0;\n DO i=1, 127\n x(i) = i + 100000.\n ENDDO\n sum=0.; sumsq2=0.\n ! standard deviation calculated with text book algorithm\n DO i=1, 127\n sum = sum +x(i)\n\n sumsq2 = sumsq2+x(i)**2\n ENDDO\n ! average\n xbar=sum/127.\n sigma1=SQRT((sumsq2-sum*xbar)/126.)\n ! second method to evaluate the standard deviation\n sumsq2=0.\n DO i=1, 127\n sumsq2=sumsq2+(x(i)-xbar)**2\n ENDDO\n sigma2=SQRT(sumsq2/126.)\n WRITE(*,*) xbar, sigma1, sigma2\n\nEND PROGRAM standard_deviation\n", "meta": {"hexsha": "66f19d2c3ddec6001b21c1e0c98d111f9c6d77a2", "size": 676, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/IntroProgramming/Fortran/program6.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/program6.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/program6.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": 20.4848484848, "max_line_length": 63, "alphanum_fraction": 0.6183431953, "num_tokens": 264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.8146038095317135}} {"text": "MODULE omp_subs\n IMPLICIT NONE\nCONTAINS\n FUNCTION calc_pi(n) RESULT(pi)\n IMPLICIT NONE\n INTEGER(8) :: accept\n REAL(8) :: r(2), pi\n INTEGER(8), INTENT(in) :: n\n INTEGER(8) :: i\n\n accept = 0\n\n !$omp parallel do private(r,i) reduction(+:accept)\n DO i = 1, n\n CALL RANDOM_NUMBER(r)\n IF (r(1)**2 + r(2)**2 <= 1) THEN\n accept = accept + 1\n END IF\n END DO\n !$omp end parallel do\n\n pi = 4.0d0 * DBLE(accept)/DBLE(n)\n\n END FUNCTION calc_pi\n\nEND MODULE omp_subs\n\nPROGRAM main\n USE omp_subs\n IMPLICIT NONE\n\n INTEGER(8) :: n\n REAL(8), PARAMETER :: pi = 2.0d0*dacos(0.0d0)\n REAL(8) :: mypi\n CHARACTER (len=64) :: arg\n\n CALL RANDOM_SEED()\n\n IF (command_argument_count() /= 1) THEN\n error STOP \"One command line argument should be passed, which is the number of iterations to perform.\"\n END IF\n\n CALL get_command_argument(1, arg)\n READ(arg,*) n\n\n mypi = calc_pi(n)\n\n WRITE(*,'(a,f12.6)') \"Calculated = \", mypi\n WRITE(*,'(a,f12.6)') \"Actual = \", pi\n\nEND PROGRAM main\n", "meta": {"hexsha": "41a3ed2a381dc6b1f74144186c6619a236530fee", "size": 1067, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modern_fotran/ParrallelComputation/2acos0/omp.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": "modern_fotran/ParrallelComputation/2acos0/omp.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": "modern_fotran/ParrallelComputation/2acos0/omp.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": 20.5192307692, "max_line_length": 110, "alphanum_fraction": 0.587628866, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8856314632529872, "lm_q1q2_score": 0.814464368358714}} {"text": "module constants_mod\r\nimplicit none\r\nreal, parameter :: pi = 3.14159\r\nend module constants_mod\r\n!\r\nmodule circle_mod\r\nuse constants_mod\r\nimplicit none\r\ncontains\r\npure elemental function circle_area(r) result(area)\r\nreal, intent(in) :: r\r\nreal :: area\r\narea = pi*r**2\r\nend function circle_area\r\nend module circle_mod\r\n!\r\nprogram imports\r\nuse circle_mod ! imports circle_area and pi\r\n! the lines below would clarify what is imported from where\r\n! use circle_mod , only: circle_area\r\n! use constants_mod, only: pi\r\n! OR\r\n! use circle_mod, only: circle_area, pi\r\nimplicit none\r\nreal, parameter :: r = 10.0\r\nprint*,circle_area(r), pi*r**2 ! 314.1590 314.1590\r\nend program imports", "meta": {"hexsha": "ff141a7d86e607856cd1120b4019ba66bbf2d5e3", "size": 688, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "imports.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": "imports.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": "imports.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": 25.4814814815, "max_line_length": 60, "alphanum_fraction": 0.726744186, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.9086178944582997, "lm_q1q2_score": 0.8143500305261706}} {"text": "!Autor: Claudio Iván Esparza Castañeda\n!Título: Multiplicación de matrices\n!Descripción: Multiplica dos matrices\n!Fecha: 30/03/2020\n\nProgram mulmat\n implicit none\n REAL, allocatable, dimension(:, :)::A, B, C\n INTEGER, dimension(0:1)::N, M\n REAL::s, t\n INTEGER::i, j, k\n WRITE(*, *) \"Dimensión de la primera matriz (filas x columnas)\"\n READ(*, *) N(0), N(1)\n WRITE(*, *) \"Dimensión de la segunda matriz (filas x columnas)\"\n READ(*, *) M(0), M(1)\n if ((N(1) .eq. M(0))) then\n allocate(A(1:N(0), 1:N(1)), B(1:M(0), 1:M(1)), C(1:N(0), 1:M(1)))\n WRITE(*, *) \"Elementos de la primera matriz:\"\n do i=1, N(0)\n do j=1, N(1)\n READ(*, *) A(i, j)\n end do\n end do\n WRITE(*, *) \"Elementos de la segunda matriz:\"\n do i=1, N(0)\n do j=1, N(1)\n READ(*, *) B(i, j)\n end do\n end do\n do i=1, N(0)\n do j=1, M(1)\n s=0\n do k=1, M(1)\n s=s+A(i, k)*B(k, j)\n end do\n C(i, j)=s\n end do\n end do\n WRITE(*, *) \"Matriz C\"\n do i=1, M(1)\n WRITE(*, *) C(i, :)\n end do\n deallocate(A, B, C)\n end if\nend Program mulmat\n\n\n\n", "meta": {"hexsha": "0253800852d037fd59f44d6ebf9559911ab807e0", "size": 1168, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "21.- MultMat/MultMat.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": "21.- MultMat/MultMat.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": "21.- MultMat/MultMat.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": 23.8367346939, "max_line_length": 70, "alphanum_fraction": 0.4905821918, "num_tokens": 441, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.8142759237074693}} {"text": "module rk_constants\n use iso_fortran_env, only: wp => real64\n implicit none\n\n ! Tableaus associated with Explicit RK methods\n public :: classic_rk4, &\n & three_eighths_rk4, &\n & midpoint, &\n & heun, &\n & ralston\n\n ! Tableaus associated with Embedded Explicit RK methods\n public :: heun_euler, &\n & fehlbery_rk12, &\n & bogacki_shampine, &\n & fehlbery_rk45, &\n & cash_karp_rk45, &\n & dormand_prince_rk45, &\n & fehlbery_rk78\n\n ! Tableaus associated with Embedded Implicit RK methods\n public :: trapezoidal, &\n & gauss_legendre4, &\n & gauss_legendre6\n\n private :: two_stage\n\ncontains\n\n subroutine midpoint(a, b, c, m)\n integer, intent(out) :: m\n real(wp) :: alpha\n real(wp), intent(out), dimension(:), allocatable :: c, b\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n m = 2\n allocate(a(m,m), b(m), c(m))\n\n alpha = 0.5_wp\n call two_stage(a, b, c, m, alpha)\n\n return\n end subroutine midpoint\n\n subroutine heun(a, b, c, m)\n integer, intent(out) :: m\n real(wp) :: alpha\n real(wp), intent(out), dimension(:), allocatable :: c, b\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n m = 2\n allocate(a(m,m), b(m), c(m))\n\n alpha = 1._wp\n call two_stage(a, b, c, m, alpha)\n\n return\n end subroutine heun\n\n subroutine ralston(a, b, c, m)\n integer, intent(out) :: m\n real(wp) :: alpha\n real(wp), intent(out), dimension(:), allocatable :: c, b\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n m = 2\n allocate(a(m,m), b(m), c(m))\n\n alpha = 2._wp/3._wp\n call two_stage(a, b, c, m, alpha)\n\n return\n end subroutine ralston\n\n subroutine two_stage(a, b, c, m, alpha)\n integer, intent(in) :: m\n real(wp), intent(in) :: alpha\n real(wp), intent(out), dimension(m) :: c, b\n real(wp), intent(out), dimension(m,m) :: a\n\n c = [0._wp, alpha]\n b = [(1._wp - (1._wp/(2._wp*alpha))), (1._wp/(2._wp*alpha))]\n\n a = 0._wp\n a(2,1) = alpha\n\n return\n end subroutine two_stage\n\n\n\n subroutine classic_rk4(a, b, c, m)\n integer, intent(out) :: m\n real(wp), intent(out), dimension(:), allocatable :: c, b\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n m = 4\n allocate(a(m,m), b(m), c(m))\n\n c = [0._wp, 0.5_wp, 0.5_wp, 1._wp]\n b = [1._wp/6._wp, 1._wp/3._wp, 1._wp/3._wp, 1._wp/6._wp]\n\n a = 0._wp\n a(2,1) = 0.5_wp\n a(3,2) = 0.5_wp\n a(4,3) = 1._wp\n\n return\n end subroutine classic_rk4\n\n subroutine three_eighths_rk4(a, b, c, m)\n integer, intent(out) :: m\n real(wp), intent(out), dimension(:), allocatable :: c, b\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n m = 4\n allocate(a(m,m), b(m), c(m))\n\n c = [0._wp, 1._wp/3._wp, 2._wp/6._wp, 1._wp]\n b = [1._wp/8._wp, 3._wp/8._wp, 3._wp/8._wp, 1._wp/8._wp]\n\n a = 0._wp\n a(2,1) = 0.5_wp\n a(3,1:2) = [-1._wp/3._wp, 1._wp]\n a(4,1:3) = [1._wp, -1._wp, 1._wp]\n\n return\n end subroutine three_eighths_rk4\n\n\n\n subroutine heun_euler(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 2\n m = 2\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n ! There is already a routine to calculate the heun coefficients - just\n ! reuse it for the first row of `b`, then set bstar\n\n call heun(a, b, c, m)\n bstar = [1._wp, 0._wp]\n\n return\n end subroutine heun_euler\n\n subroutine fehlbery_rk12(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 2\n m = 3\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 0.5_wp, 1.0_wp]\n b = [1._wp/512._wp, 255._wp/256._wp, 1._wp/512._wp]\n bstar = [1._wp/256._wp, 255._wp/256._wp, 0._wp]\n\n a = 0._wp\n a(2,1) = 0.5_wp\n a(3,:) = [1._wp/256._wp, 255._wp/256._wp, 0._wp]\n\n return\n end subroutine fehlbery_rk12\n\n subroutine bogacki_shampine(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 3\n m = 4\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 0.5_wp, 0.75_wp, 1.0_wp]\n b = [2._wp/9._wp, 1._wp/3._wp, 4._wp/9._wp, 0._wp]\n bstar = [7._wp/24._wp, 1._wp/4._wp, 1._wp/3._wp, 1._wp/8._wp]\n\n a = 0._wp\n a(2,1) = 0.5_wp\n a(3,2) = 0.75_wp\n a(4,1:3) = [2._wp/9._wp, 1._wp/3._wp, 4._wp/9._wp]\n\n return\n end subroutine bogacki_shampine\n\n subroutine fehlbery_rk45(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 5\n m = 6\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 0.25_wp, 3._wp/8._wp, 12._wp/13._wp, 1._wp, 0.5_wp]\n b = [16._wp/135._wp, 0._wp, 6656._wp/12825._wp, &\n & 28561._wp/56430._wp, -9._wp/50._wp, 2._wp/55._wp]\n bstar = [25._wp/216._wp, 0._wp, 1408._wp/2565._wp, 2197._wp/4104._wp, &\n & -1._wp/5._wp, 0._wp]\n\n a = 0._wp\n a(2,1) = 1._wp/4._wp\n a(3, 1:2) = [3._wp/32._wp, 9._wp/32._wp]\n a(4, 1:3) = [1932._wp/2197._wp, -7200._wp/2197._wp, 7296._wp/2197._wp]\n a(5, 1:4) = [439._wp/216._wp, -8._wp, 3680._wp/513._wp, -845._wp/4104._wp]\n a(6, 1:5) = [-8._wp/27._wp, 2._wp, -3544._wp/2565._wp, 1859._wp/4104._wp, &\n & -11._wp/40._wp]\n\n return\n end subroutine fehlbery_rk45\n\n subroutine cash_karp_rk45(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 5\n m = 6\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 1._wp/5._wp, 3._wp/10._wp, 3._wp/5._wp, 1._wp, &\n & 7._wp/8._wp]\n b = [37._wp/378._wp, 0._wp, 250._wp/621._wp, 125._wp/594._wp, &\n & 0._wp, 512._wp/1771._wp]\n bstar = [2825._wp/27648._wp, 0._wp, 18575._wp/48384._wp, &\n & 13525._wp/55296._wp, 277._wp/14336._wp, 1._wp/4._wp]\n\n a = 0._wp\n a(2,1) = 1._wp/5._wp\n a(3, 1:2) = [3._wp/40._wp, 9._wp/40._wp]\n a(4, 1:3) = [3._wp/10._wp, -9._wp/10._wp, 6._wp/5._wp]\n a(5, 1:4) = [-11._wp/54._wp, 5._wp/2._wp, -70._wp/27._wp, 35._wp/27._wp]\n a(6, 1:5) = [1631._wp/55296._wp, 175._wp/512._wp, 575._wp/13824._wp, &\n & 44275._wp/110592._wp, 253._wp/4096._wp]\n\n return\n end subroutine cash_karp_rk45\n\n subroutine dormand_prince_rk45(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 5\n m = 7\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 1._wp/5._wp, 3._wp/10._wp, 4._wp/5._wp, 8._wp/9._wp, &\n & 1._wp, 1._wp]\n b = [35._wp/384._wp, 0._wp, 500._wp/1113._wp, 125._wp/192._wp, &\n & -2187._wp/6784._wp, 11._wp/84._wp, 0._wp]\n bstar = [5179._wp/57600._wp, 0._wp, 7571._wp/16695._wp, &\n & 393._wp/640._wp, -92097._wp/339200._wp, 187._wp/2100._wp, &\n & 1._wp/40._wp]\n\n a = 0._wp\n a(2,1) = 1._wp/5._wp\n a(3, 1:2) = [3._wp/40._wp, 9._wp/40._wp]\n a(4, 1:3) = [44._wp/45._wp, -56._wp/15._wp, 32._wp/9._wp]\n a(5, 1:4) = [19372._wp/6561._wp, -25360._wp/2187._wp, 64448._wp/6561._wp, &\n & -212._wp/729._wp]\n a(6, 1:5) = [9017._wp/3168._wp, -355._wp/33._wp, 46732._wp/5247._wp, &\n & 49._wp/176._wp, -5103._wp/18656._wp]\n a(7, 1:6) = [35._wp/384._wp, 0._wp, 500._wp/1113._wp, 125._wp/192._wp, &\n & -2187._wp/6784._wp, 11._wp/84._wp]\n\n return\n end subroutine dormand_prince_rk45\n\n subroutine fehlbery_rk78(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 7\n m = 13\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [0._wp, 2._wp/27._wp, 1._wp/9._wp, 1._wp/6._wp, 5._wp/12._wp, &\n & 0.5_wp, 5._wp/6._wp, 1._wp/6._wp, 2._wp/3._wp, &\n & 1._wp/3._wp, 1._wp, 0._wp, 1._wp]\n b = [41._wp/840._wp, 0._wp, 0._wp, 0._wp, 0._wp, 34._wp/105._wp, &\n & 9._wp/35._wp, 9._wp/35._wp, 9._wp/280._wp, 9._wp/280._wp, &\n & 41._wp/840._wp, 0._wp, 0._wp]\n bstar = [0._wp, 0._wp, 0._wp, 0._wp, 0._wp, 34._wp/105._wp, &\n & 9._wp/35._wp, 9._wp/35._wp, 9._wp/280._wp, &\n & 9._wp/280._wp, 0._wp, 41._wp/840._wp, 41._wp/840._wp]\n\n a = 0._wp\n a(2,1) = 2._wp/27._wp\n a(3, 1:2) = [1._wp/36._wp, 1._wp/12._wp]\n a(4, 1:3) = [1._wp/24._wp, 0._wp, 1._wp/8._wp]\n a(5, 1:4) = [5._wp/12._wp, 0._wp, -25._wp/16._wp, 25._wp/16._wp]\n a(6, 1:5) = [1._wp/20._wp, 0._wp, 0._wp, 1._wp/4._wp, 1._wp/5._wp]\n a(7, 1:6) = [-25._wp/108._wp, 0._wp, 0._wp, 125._wp/108._wp, &\n & -65._wp/27._wp, 125._wp/54._wp]\n a(8, 1:7) = [31._wp/300._wp, 0._wp, 0._wp, 0._wp, 61._wp/225._wp, &\n & -2._wp/9._wp, 13._wp/900._wp]\n a(9, 1:8) = [2._wp, 0._wp, 0._wp, -53._wp/6._wp, 704._wp/45._wp, &\n & -107._wp/9._wp, 67._wp/90._wp, 3._wp]\n a(10, 1:9) = [-91._wp/108._wp, 0._wp, 0._wp, 23._wp/108._wp, &\n & -976._wp/135._wp, 311._wp/54._wp, -19._wp/60._wp, &\n & 17._wp/6._wp, -1._wp/12._wp]\n a(11, 1:10) = [2383._wp/4100._wp, 0._wp, 0._wp, -341._wp/164._wp, &\n & 4496._wp/1025._wp, -301._wp/82._wp, 2133._wp/4100._wp, &\n & 45._wp/82._wp, 45._wp/164._wp, 18._wp/41._wp]\n a(12, 1:11) = [3._wp/205._wp, 0._wp, 0._wp, 0._wp, 0._wp, -6._wp/41._wp, &\n & -3._wp/205._wp, -3._wp/41._wp, 3._wp/41._wp, 6._wp/41._wp, &\n & 0._wp]\n a(13, 1:12) = [-1777._wp/4100._wp, 0._wp, 0._wp, -341._wp/164._wp, &\n & 4496._wp/1025._wp, -289._wp/82._wp, 2193._wp/4100._wp, &\n & 51._wp/82._wp, 33._wp/164, 19._wp/41._wp, 0._wp, 1._wp]\n\n return\n end subroutine fehlbery_rk78\n\n subroutine trapezoidal(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 2\n m = 2\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [ 0._wp, 1._wp ]\n\n a = 0._wp\n a(2,:) = [ 0.5_wp, 0.5_wp ]\n\n b = [ 0.5_wp, 0.5_wp ]\n bstar = [ 1._wp, 0._wp ]\n\n return\n end subroutine trapezoidal\n\n subroutine gauss_legendre4(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 4\n m = 2\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [ 0.5_wp - sqrt(3._wp)/6._wp, 0.5_wp + sqrt(3._wp)/6._wp ]\n\n a(1,:) = [ 0.25_wp, 0.25_wp - sqrt(3._wp)/6._wp ]\n a(2,:) = [ 0.25_wp + sqrt(3._wp)/6._wp, 0.25_wp]\n\n b = [ 0.25_wp, 0.25_wp ]\n bstar = [ 0.25_wp + 0.25_wp*sqrt(3._wp), 0.25_wp - 0.25_wp*sqrt(3._wp) ]\n\n return\n end subroutine gauss_legendre4\n\n subroutine gauss_legendre6(a, b, bstar, c, m, p)\n integer, intent(out) :: m, p\n real(wp), intent(out), dimension(:), allocatable :: c, b, bstar\n real(wp), intent(out), dimension(:,:), allocatable :: a\n\n p = 6\n m = 3\n allocate(a(m,m), b(m), bstar(m), c(m))\n\n c = [ 0.25_wp - 0.1_wp*sqrt(15._wp), 0.5_wp, 0.25_wp + 0.1_wp*sqrt(15._wp) ]\n\n a(1,:) = [ 5._wp/36._wp, 2._wp/9._wp - 1._wp/15._wp * sqrt(15._wp), 5._wp/36._wp - 1._wp/30._wp*sqrt(15._wp) ]\n a(2,:) = [ 5._wp/36._wp + 1._wp/24._wp * sqrt(15._wp), 2._wp/9._wp, 5._wp/36._wp - 1._wp/24._wp * sqrt(15._wp) ]\n a(3,:) = [ 5._wp/36._wp + 1._wp/30._wp * sqrt(15._wp), 2._wp/9._wp + 1._wp/15._wp * sqrt(15._wp), 5._wp/36._wp ]\n\n b = [ 5._wp/18._wp, 4._wp/9._wp, 5._wp/18._wp ]\n bstar = [ -5._wp/6._wp, 8._wp/3._wp, -5._wp/6._wp ]\n\n return\n end subroutine gauss_legendre6\n\nend module rk_constants\n", "meta": {"hexsha": "ebddd29f985c14577f6ef870bdcfdecdd8f629a6", "size": 13248, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rk_constants.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/rk_constants.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/rk_constants.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": 34.5, "max_line_length": 117, "alphanum_fraction": 0.5030948068, "num_tokens": 5469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.8142738275028183}} {"text": "module stats\n\nuse assert, only: wp\n\nimplicit none (type, external)\n\ncontains\n\n!***********************************************************************************************************************************\n! CNR\n!\n! Combinations of N things taken R at a time.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION CNR (N,R) RESULT (Y)\n\nINTEGER, INTENT(IN) :: N, R\nINTEGER :: I, J\n\nY = 1._wp\nJ = N\n\nDO I = N-R, 1, -1\n Y = Y * real(j,wp)/real(i,wp)\n J = J - 1\nEND DO\n\nEND FUNCTION CNR\n\n!***********************************************************************************************************************************\n! PNR\n!\n! Permutations of N things taken R at a time.\n!***********************************************************************************************************************************\n\nelemental real(wp) FUNCTION PNR (N,R) RESULT (Y)\n\nINTEGER, INTENT(IN) :: N, R\nINTEGER :: I, J\n\nY = 1._wp\nJ = N\n\nDO I = N-R, 1, -1\n Y = Y * real(j,wp)/real(i,wp)\n J = J - 1\nEND DO\n\nDO I = R, 1, -1\n Y = Y * real(i,wp)\nEND DO\n\n\nEND FUNCTION PNR\n\n\n\n!***********************************************************************************************************************************\n! LINREG\n!\n! Real linear regression.\n!***********************************************************************************************************************************\n\nelemental SUBROUTINE LINREG (M, B, R)\n\nUSE GLOBAL\n\nreal(wp), INTENT(OUT) :: M, B, R\n\nM = (NN*SUMXY-SUMX*SUMY)/(NN*SUMX2-SUMX**2)\nB = (SUMY*SUMX2-SUMX*SUMXY)/(NN*SUMX2-SUMX**2)\nR = (SUMXY-SUMX*SUMY/NN)/SQRT((SUMX2-SUMX**2/NN)*(SUMY2-SUMY**2/NN))\n\n\nEND SUBROUTINE LINREG\n\n!***********************************************************************************************************************************\n! CLINREG\n!\n! Complex linear regression.\n!***********************************************************************************************************************************\n\nelemental SUBROUTINE CLINREG (M, B, R)\n\nUSE GLOBAL, only: cnn, csumxy, csumx, csumx2, csumy, csumy2\n\nCOMPLEX(wp), INTENT(OUT) :: M, B, R\n\nM = (CNN*CSUMXY-CSUMX*CSUMY)/(CNN*CSUMX2-CSUMX**2)\nB = (CSUMY*CSUMX2-CSUMX*CSUMXY)/(CNN*CSUMX2-CSUMX**2)\nR = (CSUMXY-CSUMX*CSUMY/CNN)/SQRT((CSUMX2-CSUMX**2/CNN)*(CSUMY2-CSUMY**2/CNN))\n\nEND SUBROUTINE CLINREG\n!***********************************************************************************************************************************\n! RLINREG\n!\n! Rational linear regression.\n!***********************************************************************************************************************************\n\nelemental SUBROUTINE RLINREG (NM, DM, NB, DB, R)\nuse rat, only: rmul, rsub, rdiv\n\nUSE GLOBAL\n\nINTEGER, INTENT(OUT) :: NM, DM, NB, DB\nreal(wp), INTENT(OUT) :: R\nINTEGER :: NUM, DEN, NUM2, DEN2, NUM3, DEN3, NUM4, DEN4\nreal(wp) :: DNN, DSUMX, DSUMX2, DSUMY, DSUMY2, DSUMXY\n\n\nCALL RMUL(RNNN,RDNN,RNSUMXY,RDSUMXY,NUM,DEN)\nCALL RMUL(RNSUMX,RDSUMX,RNSUMY,RDSUMY,NUM2,DEN2)\nCALL RSUB(NUM,DEN,NUM2,DEN2,NUM3,DEN3)\nCALL RMUL(RNNN,RDNN,RNSUMX2,RDSUMX2,NUM,DEN)\nCALL RMUL(RNSUMX,RDSUMX,RNSUMX,RDSUMX,NUM2,DEN2)\nCALL RSUB(NUM,DEN,NUM2,DEN2,NUM4,DEN4)\n\nCALL RDIV(NUM3,DEN3,NUM4,DEN4,NM,DM)\n\nCALL RMUL(RNSUMY,RDSUMY,RNSUMX2,RDSUMX2,NUM,DEN)\nCALL RMUL(RNSUMX,RDSUMX,RNSUMXY,RDSUMXY,NUM2,DEN2)\nCALL RSUB(NUM,DEN,NUM2,DEN2,NUM3,DEN3)\nCALL RMUL(RNNN,RDNN,RNSUMX2,RDSUMX2,NUM,DEN)\nCALL RMUL(RNSUMX,RDSUMX,RNSUMX,RDSUMX,NUM2,DEN2)\nCALL RSUB(NUM,DEN,NUM2,DEN2,NUM4,DEN4)\n\nCALL RDIV(NUM3,DEN3,NUM4,DEN4,NB,DB)\n\nDNN = DBLE(RNNN)/DBLE(RDNN)\nDSUMX = DBLE(RNSUMX)/DBLE(RDSUMX)\nDSUMX2 = DBLE(RNSUMX2)/DBLE(RDSUMX2)\nDSUMY = DBLE(RNSUMY)/DBLE(RDSUMY)\nDSUMY2 = DBLE(RNSUMY2)/DBLE(RDSUMY2)\nDSUMXY = DBLE(RNSUMXY)/DBLE(RDSUMXY)\n\nR = (DSUMXY-DSUMX*DSUMY/DNN)/SQRT((DSUMX2-DSUMX**2/DNN)*(DSUMY2-DSUMY**2/DNN))\n\nEND SUBROUTINE RLINREG\n\n\nend module stats\n", "meta": {"hexsha": "4c8b18dfd431d8d33652f09e85487f8927d074f1", "size": 3938, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stats.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/stats.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/stats.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": 27.7323943662, "max_line_length": 132, "alphanum_fraction": 0.4545454545, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.8141680916138093}} {"text": " REAL*8 FUNCTION DECLINATION_FN(DAY_OF_YEAR,DAYS_IN_YEAR,\n 1 PI)\n IMPLICIT NONE\nc\n\n REAL*8 MAXDECLINATION, PI\n INTEGER*4 DAYS_IN_YEAR, DAY_OF_YEAR\n\tMAXDECLINATION = 23.45\n\tDECLINATION_FN =MAXDECLINATION * PI/180.0 *\n 1 SIN(PI/180.0 *(360D0*DBLE(DAY_OF_YEAR)/\n 2 DBLE(DAYS_IN_YEAR)-80D0))\nc\nc//! Equation: 1\nc//! Description: Approximates declination angle for each day: RESULT \\\nc//! is in RADIANS. Assume sine wave, with dec=23.45 on 21 June. \\\\ \nc//! INPUTS: Day-number of the year; Number of days in the year;\\\nc//! mathematical constant, PI. \nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: Decl = D_{max} * \\pi/180 * SIN(\\pi/180*(360*DoY\\over{DinY}-80))\nc \nc//! Variable: Decl \nc//! Description: returned value of the suns's declination\nc//! Units: Radians\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: D_{max}\nc//! Description: maximum value of the suns's declination\nc//! Value: 23.45\nc//! Units: Degrees\nc//! Type: REAL*8\nc \nc//! Variable: \\pi \nc//! Description: Mathematical constant, pi 3.1415... \nc//! Units: Radian\nc//! Type: REAL*8\nc\nc//! Variable: DoY\nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable: DinY\nc//! Description: Total number of Days in year,(leap year=366)\nc//! Units: none \nc//! Type: Integer \nc\n RETURN \n END \n\n\n REAL*8 FUNCTION RADIAN_TO_DEGREE_FN()\n IMPLICIT NONE\nc** 360 degrees is 2*PI radians:\n\n\tRADIAN_TO_DEGREE_FN = 180.0/(2.0*ASIN(1.0))\nc\nc//! Equation: 2\nc//! Description: a value for the number of degrees in 1 radian \\\\\nc//! INPUTS: none\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: R2D = 180.0 \\over{(2.0*ASIN(1.0)} \nc \nc//! Variable: R2D \nc//! Description: returned value: degrees in 1 radian\nc//! Units: Degree/radian\nc//! SET\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION DEGREE_TO_RADIAN_FN()\n IMPLICIT NONE\nc** 360 degrees is 2*PI radians\nc** 1 degree is approx 0.01745 radians:\n\n\tDEGREE_TO_RADIAN_FN = 2.0*ASIN(1.0)/180.0\nc\nc//! Equation: 3\nc//! Description: a value for the number of radians in 1 degree \\\\\nc//! INPUTS: none\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: D2R = 2.0*ASIN(1.0) \\over{180.0} \nc \nc//! Variable: D2R \nc//! Description: returned value: radians in 1 degree\nc//! Units: Radian/Degree\nc//! SET\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION PIVALUE_FN()\n IMPLICIT NONE\nc** Returns the value PI (3.14157...) \n\n\tPIVALUE_FN = 2.0*ASIN(1.0) \nc\nc//! Equation: 4\nc//! Description: Sets the value of Pi \\\\\nc//! INPUTS: none\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: Pi = 2.0*ASIN(1.0) \nc \nc//! Variable: Pi \nc//! Description: mathematical constant number Pi, 3.14159...\nc//! Units: none \nc//! SET\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION DAYLENGTH_FN(LATITUDE_RAD, DECLINATION,\n 1 PI)\n IMPLICIT NONE\nc** calculate the day-length, use declination and latitude \n\n REAL*8 DECLINATION, LATITUDE_RAD\n REAL*8 PI, COSHS, HS\n REAL*8 ALTANGLE\n\tALTANGLE = -0.833*PI/180.0\n\tCOSHS = -((SIN(LATITUDE_RAD)*SIN(DECLINATION)-SIN(ALTANGLE)) /\n 1 (COS(LATITUDE_RAD)*COS(DECLINATION))) \n\tHS = ACOS(COSHS)*180/PI \n\tDAYLENGTH_FN = HS*2/15.0\nc\nc//! Equation: 5\nc//! Description: calculates the daylength in hours. No Account is \\\nc//! taken of altitude, or longitude. \\\\\nc//! INPUTS: Latitude; Solar declination; mathematical constant, PI\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: daylen=180*2*ACOS( (SIN(Lat)*SIN(Decl)-SIN(altang)) \\over \\\nc//! {(COS(Lat)*COS(Decl))} ) /Pi /15.0 \\\\\nc//! altang = -0.833 \\pi/180.0\nc \nc//! Variable: daylen\nc//! Description: appproximation of daylength\nc//! Units: hours \nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: altang\nc//! Description: altitude angle (radians); calculated value at sea-level.\nc//! Value: -0.14538592....\nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Pi\nc//! Description: mathematical constant number Pi, 3.14159...\nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN \n END \n\n\n REAL*8 FUNCTION DAWN_FN(DAYLENGTH)\n IMPLICIT NONE\n\nc** calculate the time of dawn: use declination and latitude to\nc** get daylength and go from there value is local solar time.\n REAL*8 DAYLENGTH\n\tDAWN_FN = 12.0-(DAYLENGTH/2.0)\nc\nc//! Equation: 6\nc//! Description: finds the approximate time of dawn - no account is \\\nc//! taken of altitude, longitude etc. \\\\\nc//! INPUTS: Daylength\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: T_{dawn} = 12.0 - (daylen/2.0)\nc \nc//! Variable: T_{dawn} \nc//! Description: Approximate time of dawn.\nc//! Units: Local Solar time\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: daylen \nc//! Description: Approximate daylength. \nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN \n END \n\n\n REAL*8 FUNCTION DUSK_FN(DAYLENGTH)\n IMPLICIT NONE\n\nc** calculate the time of dusk: use declination and latitude \n REAL*8 DAYLENGTH\n\tDUSK_FN = 12.0+(DAYLENGTH/2.0) \nc\nc//! Equation: 7\nc//! Description: finds the approximate time of dusk - no account is \\\nc//! taken of altitude, longitude etc. \\\\\nc//! INPUTS: Daylength\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: T_{dusk} = 12.0 - (daylen/2.0)\nc \nc//! Variable: T_{dusk} \nc//! Description: Approximate time of dusk.\nc//! Units: Local Solar Time\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: daylen \nc//! Description: Approximate daylength. \nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN \n END \n\n\n INTEGER*4 FUNCTION DAY_OF_YEAR_FN(DD,MM,DAYSINYEAR)\n IMPLICIT NONE\n\n INTEGER*4 DAYSINYEAR, LEAPSHIFT\n INTEGER*4 DD, MM, JUL\nc** returns the day of the year given the month day and year.\nc** checks for leap year using DAYS_IN_YEAR\nc** \nc** These are NOT JULIAN dates (although people often refer mistakenly \nc** as such). \n\tLEAPSHIFT = 0\n\tIF(DAYSINYEAR.EQ.366) LEAPSHIFT=1\n\tIF(MM.EQ.1) THEN \n\t JUL = DD \n\tELSE IF(MM.EQ.2) THEN \n\t JUL = 31+DD \n\tELSE IF(MM.EQ.3) THEN \n\t JUL = 31+28+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.4) THEN \n\t JUL = 31+28+31+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.5) THEN\n\t JUL = 31+28+31+30+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.6) THEN \n\t JUL = 31+28+31+30+31+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.7) THEN \n\t JUL = 31+28+31+30+31+30+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.8) THEN \n\t JUL = 31+28+31+30+31+30+31+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.9) THEN \n\t JUL = 31+28+31+30+31+30+31+31+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.10) THEN \n\t JUL = 31+28+31+30+31+30+31+31+30+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.11) THEN \n\t JUL = 31+28+31+30+31+30+31+31+30+31+DD + LEAPSHIFT\n\tELSE IF(MM.EQ.12) THEN\n\t JUL = 31+28+31+30+31+30+31+31+30+31+30+DD + LEAPSHIFT\n\tENDIF \n\tDAY_OF_YEAR_FN = JUL\nc\nc//! Equation: 8\nc//! Description: finds the day of the year, starting with Jan 1 =1 \\\\\nc//! INPUTS: Day of Month; Month of year (numeric); Days in Year\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: DoY = \\sum_{i=0}^{mon-1} Dm_{i} + dd\nc \nc//! Variable: DoY \nc//! Description: Day of the year \nc//! Units: none \nc//! SET\nc//! Type: Integer \nc\nc//! Variable: mon \nc//! Description: month number \nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable: Dm_{i}\nc//! Description: Days in month (i) \nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable: dd \nc//! Description: day of the current month\nc//! Units: none \nc//! Type: Integer \nc\n RETURN \n END \n\n\n INTEGER*4 FUNCTION DAYS_IN_YEAR_FN(YYYY)\n IMPLICIT NONE\n\nc** checks the year and tests if it is a leap-year. Returns the\nc** number of days in the year (ie. 365 or 366). \n INTEGER*4 YYYY, MODVAL\n\tMODVAL=100\n\tIF( MOD(YYYY,MODVAL).EQ.0) THEN\nc** century - must be divisible by 400\n\t MODVAL=400\n\t IF( MOD(YYYY,MODVAL).EQ.0) THEN\n\t DAYS_IN_YEAR_FN=366\n\t ELSE\n\t DAYS_IN_YEAR_FN=365\n\t ENDIF\n\tELSE\nc** not a century - is it divisble by 4\n\t MODVAL=4\n\t IF( MOD(YYYY,MODVAL).EQ.0) THEN\n\t DAYS_IN_YEAR_FN=366\n\t ELSE\n\t DAYS_IN_YEAR_FN=365\n\t ENDIF\n\tENDIF\n RETURN\nc\nc//! Equation: 9\nc//! Description: calculates number of days in any year \\\\\nc//! INPUTS: Year\nc//! Bibliography: After: L. Halsall, Stats & Computing, Forest \\\nc//! Research, Forestry Commission, Alice Holt, Farnham.\nc\nc//! Case: MOD(year, 100)=0 and MOD(year,400)=0\nc//! E: DinY = 366\nc//! Case: MOD(year,100)<>0 and MOD(year,4)=0\nc//! E: DinY = 366\nc//! Case: All other conditions\nc//! E: DinY = 365\nc \nc//! Variable: DinY \nc//! Description: Number of days in a year: \\\\\nc//! If it is a century and divisible by 400, then it is a leap year \\\\\nc//! If its NOT a century but divisible by 4, then it is a leap year\nc//! Units: none \nc//! SET\nc//! Type: Integer \nc\nc//! Variable: year \nc//! Description: full year number (eg 1997, 2002 etc).\nc//! Units: none \nc//! Type: Integer \nc\n END\n\n\n\n REAL*8 FUNCTION DECLINATION2_FN(DAY_OF_YEAR)\n IMPLICIT NONE\n\nc\n REAL*8 MAXDECLINATION\n INTEGER*4 DAY_OF_YEAR\n\tMAXDECLINATION = 0.39785\n\tDECLINATION2_FN = MAXDECLINATION*SIN(4.868961+0.017203* \n 1 DAY_OF_YEAR + 0.033446*SIN(6.224111 + 0.017202*DAY_OF_YEAR))\nc\nc//! Equation: 15\nc//! Description: Approximates declination angle for each day: RESULT \\\nc//! is in RADIANS. \\\\\nc//! INPUTS: Day-number of year\nc//! Bibliography: S. Evans: SWELTER \nc\nc//! E: Decl = D_{max} * sin(4.868961+0.017203 DoY + 0.033446 \\\nc//! sin(6.22411 + 0.017202 DoY))\nc \nc//! Variable: Decl \nc//! Description: returned value of the suns's declination\nc//! Units: Radians\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: D_{max}\nc//! Description: maximum value of the suns's declination\nc//! Value: 0.39785\nc//! Units: Radians\nc//! Type: REAL*8\nc \nc//! Variable: DoY\nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\n RETURN \n END \n\n\n REAL*8 FUNCTION DAYLENGTH2_FN(LATITUDE_RAD, DAY_OF_YEAR,\n 1 PI)\n IMPLICIT NONE\n\nc** calculate the day-length, use declination and latitude \n REAL*8 LATITUDE_RAD\n REAL*8 PI\n REAL*8 AMPLITUDE \n INTEGER*4 DAY_OF_YEAR\n\tAMPLITUDE = exp((7.42+0.045*LATITUDE_RAD*180./PI))/3600.0\n\tDAYLENGTH2_FN = 12.0 + AMPLITUDE*SIN((DAY_OF_YEAR-79)*0.017121)\nc\nc//! Equation: 16\nc//! Description: calculates the daylength in hours from latitude \\\nc//! and day-number. no Account is taken of altitude, or longitude. \\\\ \nc//! INPUTS: Latitude; Day-number of year, Mathematical constant, PI\nc//! Bibliography: S. Evans: SWELTER \nc\nc//! E: daylen= 12 + Amp sin((DoY-79) 0.017121) \\\\ \nc//! Amp={exp(7.42+0.045 lat 180/\\pi )} \\over{3600}\nc \nc//! Variable: daylen\nc//! Description: appproximation of daylength. based on solar time\nc//! Units: hours \nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Amp\nc//! Description: amplitude of sine curve at relevant latitude. \nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: Pi\nc//! Description: mathematical constant number Pi, 3.14159...\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: DoY \nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\n RETURN \n END \n\n\n REAL*8 FUNCTION DAWN_HOURANGLE_FN(DECLINATION, \n 1 LATITUDE_RAD)\n IMPLICIT NONE\n\nc** find the sun-rise/sun-set solar hour-angle: ie at DAWN and DUSK\n REAL*8 DECLINATION, LATITUDE_RAD, Temp\n Temp = -TAN(LATITUDE_RAD)*TAN(DECLINATION) \n If(Temp.lt.-1) Temp = -1.0\n if(Temp.gt.1) Temp =1.0\n\tDAWN_HOURANGLE_FN = ACOS(Temp)\nc\nc//! Equation: 17\nc//! Description: calculates the sunrise/sunset hour angle for the \\\nc//! day (declination) and latitude. Answer is in Radians \\\\\nc//! INPUTS: Solar declination; Latitude\nc//! Bibliography: S. Evans: SWELTER \nc\nc//! E: hs = acos(-tan(Lat)*tan(Decl))\nc \nc//! Variable: hs \nc//! Description: returned value of the solar sunrise/set hour angle \\\nc//! uncorrected for longitude.\nc//! Units: Radians\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\n RETURN\n END\n\n REAL*8 FUNCTION RAD_ET_DAY2_FN(LATITUDE_RAD,DECLINATION,\n 1 DAWN_HOURANGLE, SOL_ELLIPSE, SOL_CONST, PI)\n IMPLICIT NONE\n\nc** caclulates the extra-terrestrial daily radiation \n REAL*8 DECLINATION, LATITUDE_RAD\n REAL*8 DAWN_HOURANGLE, SOL_CONST, PI\n REAL*8 SOL_ELLIPSE \nc\n RAD_ET_DAY2_FN = SOL_CONST*SOL_ELLIPSE*(\n 1 DAWN_HOURANGLE*SIN(LATITUDE_RAD)*SIN(DECLINATION) + \n 2 COS(LATITUDE_RAD)*COS(DECLINATION)*SIN(DAWN_HOURANGLE) )\n 3 / PI*86400\nc\nc//! Equation: 18\nc//! Description: caclulates the daily extra-terrestrial radiation \\\nc//! result in W/m2/day \\\\\nc//! INPUTS: Latitude; Solar Declination; Hour-angle of sun-rise/set;\\\nc//! Elliptical scalar for suns' orbit; Solar constant, Mathematical\\\nc//! constant, Pi\nc//! Bibliography: S. Evans: SWELTER \nc\nc//! E: RAD_{et}= S_c E (hs sin(Lat) sin(Decl) + \\\nc//! cos(lat) cos(decl) sin(hs)) \\over{\\pi} 86400\nc \nc//! Variable: RAD_{et}\nc//! Description: daily value of solar radiation outside the atmosphere\nc//! Units: W/m2/day\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: S_c\nc//! Description: Solar constant. Nb there may be slight variations \\\nc//! on this depending on the source (approx 1367)\nc//! Units: W/m2\nc//! Type: REAL*8\nc\nc//! Variable: Pi \nc//! Description: mathematical constant Pi: 3.14159...\nc//! Units: none \nc//! Type: REAL*8 \nc\nc//! Variable: hs \nc//! Description: value of the solar sunrise/set hour angle.\nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: E\nc//! Description: Solar elliptical orbit scalar\nc//! Units: none \nc//! Type: REAL*8 \nc\n RETURN\n END\n\n REAL*8 FUNCTION RAD_ET_DAY_FN(LATITUDE_RAD, \n 1 DECLINATION, DAYLENGTH, SOL_ELLIPSE,\n 2 SOL_CONST, PI)\n IMPLICIT NONE\n\n\nc** caclulates the extra-terrestiral daily radiation \n REAL*8 DECLINATION, LATITUDE_RAD\n REAL*8 SOL_CONST, PI\n REAL*8 DAYLENGTH, NOON, SOL_ELEV_FN\n REAL*8 SOL_ELEV_NOON, SOL_ELLIPSE, SOL_NOON\n\nc since the routine sol_elev has local time as an input; convert \nc noon solar time to gmt\n NOON = 12.0 ! LST\n SOL_ELEV_NOON = SOL_ELEV_FN(LATITUDE_RAD, \n 1 DECLINATION, NOON, PI)\n SOL_NOON = SOL_ELLIPSE*SOL_CONST*SIN(SOL_ELEV_NOON)\n RAD_ET_DAY_FN = SOL_NOON*2*DAYLENGTH/(PI*SIN(PI/2.0) ) \n 1 *60*60! /1000/1000 \nc\nc//! Equation: 19\nc//! Description: caclulates the daily extra-terrestrial radiation \\\nc//! result in W/m2/day \\\\\nc//! INPUTS: Latitude; Longitude; Solar declination; Daylength; \\\nc//! Solar elliptical orbit scalar; Day-number of the year;\\\nc//! Solar constant; Mathematical constant, pi.\nc//! Bibliography: none/FOREST-GROWTH\nc\nc//! E: RAD_{et}= S_{12} 2 Day_{l} / (\\pi sin(\\pi/2) \\\\\nc//! S_{12} = E S_c sin(Sol_el) \\\\\nc//! Sol_{el} = \\pi/2 - Lat + Decl \\\\\nc//! E = 1.033-0.066*\\sqrt{(1-((DoY-183)**2)/(183.**2) ) }\nc \nc//! Variable: RAD_{et}\nc//! Description: daily value of solar radiation outside the atmosphere\nc//! Units: W/m2/s\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: E \nc//! Description: Elliptical scalar for the orbit of the sun \nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: S_c\nc//! Description: Solar constant. Nb there may be slight variations \\\nc//! on this depending on the source (eg 1367.0)\nc//! Units: W/m2 \nc//! Type: REAL*8\nc\nc//! Variable: Pi \nc//! Description: mathematical constant Pi: 3.14159...\nc//! Units: none \nc//! Type: REAL*8 \nc\nc//! Variable: Day_l\nc//! Description: day length\nc//! Units: hours \nc//! Type: REAL*8 \nc\nc//! Variable: DoY \nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\n RETURN\n END\n\n REAL*8 FUNCTION RAD_ET_DAY3_FN(LATITUDE_RAD, \n 1 DECLINATION, SOL_ELLIPSE, DAWN, DUSK,\n 2 SOL_CONST, PI)\n IMPLICIT NONE\n\n\nc** caclulates the extra-terrestrial daily radiation \n REAL*8 DECLINATION, LATITUDE_RAD\n REAL*8 SOL_CONST, PI, SOL_ELLIPSE\n REAL*8 SOLAR_TIME, SOL_ELEV_FN\n REAL*8 SOL_NOW, SIN_SOL_ELEV, DAWN, DUSK\n INTEGER i\n\n RAD_ET_DAY3_FN = 0.0\n DO i=0,288\n SOLAR_TIME = real(i)/12.0\n* DO SOLAR_TIME = 0,24, 1/12.0\nc** step throughout the day in 5 min intervals\n\tIF((SOLAR_TIME.GE.DAWN).AND.(SOLAR_TIME.LT.DUSK)) THEN\n\t SIN_SOL_ELEV = SIN( SOL_ELEV_FN(LATITUDE_RAD, \n 1 DECLINATION, SOLAR_TIME, PI) )\n\t SOL_NOW = MAX(0.0d0,SOL_ELLIPSE*SOL_CONST*SIN_SOL_ELEV)*60*5\n\t RAD_ET_DAY3_FN = RAD_ET_DAY3_FN + SOL_NOW\n\tENDIF\n ENDDO\nc\nc//! Equation: 20\nc//! Description: caclulates the daily extra-terrestrial radiation \\\nc//! by 5 minute interation using solar elevation result in W/m2/day. \\\nc//! This functions call a solar elevation fuunction internally. \\\\\nc//! INPUTS: Latitude; Longitude; Solar Declination; scalar of\\\nc//! sun's elliptical orbit; Day-number of the year; Solar constant;\\\nc//! Mathematical constant, pi\nc//! Bibliography: C.J.T Spitters et al. (1986); Agric & Forest Met \\\nc//! 38:217-229\nc\nc//! E: RAD_{et}= \\sum_{t=0}^{24*12} max(0, S_c E sin(Sol_{el}) 300) \\\\\nc//! if(t>=dawn and t<= dusk)\nc \nc//! Variable: RAD_{et}\nc//! Description: daily value of solar radiation outside the atmosphere\nc//! Units: W/m2/s\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Sol_{el}\nc//! Description: Solar Elevation; returned through SOL_ELEV_FN\nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: E \nc//! Description: Solar elliptical scalar \nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Dawn\nc//! Description: Time of Sunrise (Local Solar time)\nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Dusk\nc//! Description: Time of Sunset (Local Solar time)\nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: S_c\nc//! Description: Solar constant. Nb there may be slight variations \\\nc//! on this depending on the source (1367.0)\nc//! Units: W/m2 \nc//! Type: REAL*8\nc\nc//! Variable: Pi \nc//! Description: mathematical constant Pi: 3.14159...\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: DoY \nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\n RETURN\n END\n\n REAL*8 FUNCTION VP_SAT_FN(TEMP_C)\n IMPLICIT NONE\n\nc** Returns the saturated air pressure for a given temperature\n REAL*8 TEMP_C\nc\n VP_SAT_FN = 6.1078*exp(17.269*TEMP_C/(TEMP_C+237.3))\nc\nc//! Equation: 21\nc//! Description: Returns saturated vapour pressure for a temperature\\\\\nc//! INPUTS: Temperature\nc//! Bibliography: S Evans: SWELTER, Groff-Gratch equation\nc\nc//! E: VP_{sat} = 6.1078 exp{( {17.269 T}\\over{(T+237.3)} )}\nc\nc//! Variable: VP_{sat}\nc//! Description: saturated vapour pressure at a given temperature\nc//! Units: mbar\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: T\nc//! Description: Air temperature \nc//! Units: Degrees C \nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION SOL_ELEV_FN(LATITUDE_RAD,\n 1 DECLINATION, SOLAR_TIME, PI)\n IMPLICIT NONE\n\nc function returns the elevation (radians), deviation of the sun from\nc the horizontal to the vertical. Also referred to as the solar \nc altitude angle.\n\t\t\t\t\t\t\t\t\t\t\n REAL*8 LATITUDE_RAD\n REAL*8 DECLINATION, H, PI\n REAL*8 H1, SOLAR_TIME\n\t\t\t\t\t\t\t\t\t\n H1 = 15.*(SOLAR_TIME-12.0) ! degrees \n H = H1/180*PI ! radians \n SOL_ELEV_FN = ASIN( COS(LATITUDE_RAD)*COS(DECLINATION)*COS(H)\n 1 + SIN(LATITUDE_RAD)*SIN(DECLINATION) )\nc//! Equation: 22\nc//! Description: Returns solar elevation angle at time of the day \\\nc//! and day of the year. \\\\\nc//! INPUTS: Latitude; Longitude; Declination; \\\\\nc//! Local Solar time; mathematical constant, pi\nc//! Bibliography: C GronBeck, 1999; Sun Angle (web pages)\nc\nc//! E: SOL_{el} = asin(sin(Lat) sin(Decl) + cos(Lat) cos(Decl) \\\nc//! cos(H) \\\\\nc//! H = 15(Lst-12) \\pi /180.0 \nc\nc//! Variable: SOL_{el}\nc//! Description: Solar elevation of the sun\nc//! Units: Radians \nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site \nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: declination of sun (radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Lst\nc//! Description: Local solar time\nc//! Units: (hour) \nc//! Type: REAL*8\nc\nc//! Variable: \\pi\nc//! Description: Mathematical constant, pi\nc//! Units: (radians)\nc//! Type: REAL*8 \nc\n RETURN\n END\n\n\t\t\t\t\t\t\t\t\t\t\n REAL*8 FUNCTION AZIMUTH_FN(LATITUDE_RAD, DECLINATION,\n 1 SOL_ELEV)\n IMPLICIT NONE\n\nc function returns the azimuth angle (in radians): Angular distance\nc between SOUTH and the projection of the line of sight to the\nc sun on the ground.\n\t\t\t\t\t\t\t\t\t\t\n REAL*8 LATITUDE_RAD\n REAL*8 DECLINATION, SOL_ELEV, SIGN, HOURANG\n\nc check the sign of the hour-angle. Firstly convert back to hour-angle\nc using latitude, declination and elevation.\n HOURANG = ACOS( \n 1 (SIN(SOL_ELEV)-SIN(LATITUDE_RAD)*SIN(DECLINATION))/ \n 2 (COS(LATITUDE_RAD)*COS(DECLINATION) ) )\n SIGN = 1.0\n IF(HOURANG.LT.0) SIGN=-1.0\n\t\t\t\t\t\t\t\t\t\n AZIMUTH_FN = SIGN*ACOS( (SIN(SOL_ELEV)*SIN(LATITUDE_RAD) -\n 1 SIN(DECLINATION)) / (COS(SOL_ELEV)*COS(LATITUDE_RAD) ) )\nc//! Equation: 23\nc//! Description: Returns azimuth angle at any time of the day and \\\nc//! day of the year. \\\\\nc//! INPUTS: Latitude; solar declination; Solar elevation; \\\nc//! Mathematical constant, pi\nc//! Bibliography: C GronBeck, 1999; Sun Angle (web pages)\nc\nc//! E: Az = acos( {sin(Sol_{el}) sin(Lat) - sin(Decl)} \\\nc//! /over{cos(Sol_{el}) cos(Decl)} \\\\\nc//! and: the sign of Az is the same as the sign of the hour-angle.\nc\nc//! Variable: Az \nc//! Description: Azimuth angle of the sun. \nc//! Units: Radians \nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site \nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: Decl\nc//! Description: solar declination\nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: Sol_{el} \nc//! Description: Solar elevation \nc//! Units: Radians\nc//! Type: REAL*8 \nc\nc//! Variable: \\pi\nc//! Description: Mathematical constant, pi\nc//! Units: (radians)\nc//! Type: REAL*8 \nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RAD_TERRA_DAY_FN(RAD_ET_DAY, \n 1 LATITUDE_RAD, CLOUD_COVER, BETA)\n IMPLICIT NONE\n\nc converts extra-terrestiral radiation to surface radiation.\n REAL*8 RAD_ET_DAY, LATITUDE_RAD \n REAL*8 CLOUD_COVER\n REAL*8 ALPHA, BETA , SIGMA\nc\nc** Angstrom tubidity factor related to aerosol size & properties\n ALPHA = 18.0-64.884*(1-1.3614*COS(LATITUDE_RAD))\n SIGMA = 0.03259\n Alpha = alpha*4.1842*100*100 ! convert from cal/cm to w/m2\nc another fudge to try and transmit less light on heavy cloud days\nc if(cloud_cover.gt.1.0) alpha = alpha*2\nc if(cloud_cover.lt.0.15) then\nc cloud_cover = cloud_cover/1.4\nc alpha = 0.0\nc endif\n sigma = .02*LOG(max(cloud_cover,.001d0))+Sigma\nc print*, 'in rad terra',rad_et_day,beta,sigma,cloud_cover, alpha\n RAD_TERRA_DAY_FN = RAD_ET_DAY*(BETA-SIGMA*CLOUD_COVER*10)-ALPHA\nc\nc//! Equation: 24\nc//! Description: Converts extra-terrestrial radiation to terrestrial \\\nc//! radiation uncorrected for site altitude. \\\\ \nc//! INPUTS: Extra-terrestrial radiation; Latitude; cloud-cover; \\\nc//! Angstrom (beta) turbidity\nc//! Bibliography: S. Evans:SWELTER; Nikolov & Zeller (1992)\nc\nc//! E: RAD_{terra} = RAD_{et} (\\beta -\\sigma 10 Cld) - \\alpha \\\\\nc//! \\alpha = 18.0-64.884*(1-1.3614*cos(Lat)) \\\\\nc//! \\sigma = 0.03259 \nc\nc//! Variable: RAD_{terra}\nc//! Description: Terrestrial radiation on a horizonatal plane \\\nc//! for the given latitude and day.\nc//! Units: W/m2/d\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{et}\nc//! Description: Extra-Terrestrial radiation above the atmosphere \\\nc//! for the given latitude and day.\nc//! Units: W/m2/d\nc//! Type: REAL*8\nc\nc//! Variable: \\alpha \nc//! Description: Angstrom tubidity factor related to aerosol size & \\\nc//! properties\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: \\beta\nc//! Description: Angstrom tubidity factor: max clear sky transmittance\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: \\sigma \nc//! Description: Angstrom tubidity factor: Absorption by cloud cover\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\nc//! Variable: Cld \nc//! Description: Cloudiness of the day \nc//! Units: proportion \nc//! Type: REAL*8\nc\n RETURN\n END\n\n REAL*8 FUNCTION DIFFPROP_DAY_FN(TRANS_PROP_DAY)\n IMPLICIT NONE\n\nc** determines the proportion of light that is diffuse on a daily \nc** basis\n REAL*8 TRANS_PROP_DAY\nc\n IF(TRANS_PROP_DAY.LT.0.07) THEN\n\tDIFFPROP_DAY_FN = 1.0\n ELSE IF(TRANS_PROP_DAY.LT.0.35) THEN\n\tDIFFPROP_DAY_FN = 1.0-2.3*(TRANS_PROP_DAY-0.07)**2\n ELSE IF(TRANS_PROP_DAY.LT.0.75) THEN\n\tDIFFPROP_DAY_FN = 1.33-1.46*TRANS_PROP_DAY\n ELSE\n\tDIFFPROP_DAY_FN = 0.23\n ENDIF\nc\nc//! Equation: 25\nc//! Description: The proportion of light reaching the ground that \\\nc//! is made up of diffuse component \\\\\nc//! INPUTS: proportion of extra-terrestrial radiation to terrestrial \\\nc//! radiation transmitted\nc//! Bibliography: Spitters Et al (1986), Agric & Forest Meteo \\\nc//! 38:217-229; de Jong (1980).\nc \nc//! Case: Tran < 0.07\nc//! E: Diff_{prop} = 1.0\nc//! Case: 0.07<= Tran < 0.35\nc//! E: Diff_{prop} = 1-0.23(Tran - 0.07)^{2}\nc//! Case: 0.35<= Tran < 0.75\nc//! E: Diff_{prop} = 1.33 - 1.46 Tran\nc//! Case: 0.75 <= Tran\nc//! E: Diff_{prop} = 0.23\nc\nc//! Variable: Diff_{prop}\nc//! Description: Proportion of daily terrestrial radiation that is \\\nc//! diffuse \\\\\nc//! INPUTS: Extra-terrestrial daily radiation; Terrestrial daily \\\nc//! radiation\nc//! Units: none (Ratio)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: Tran \nc//! Description: Proportion of Terrestrial radiation to \\\nc//! Extra-terrestrial radiation\nc//! Units: none (Ratio)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION SOLAR_ELLIPSE_FN(DAY_OF_YEAR, \n 1 DAYS_IN_YEAR, PI)\n IMPLICIT NONE\n\nc** calculates the scalar of the elliptical orbit of the sun around \nc** the earth. About +/- 3%; Max in mud-summer\n REAL*8 GAMMA, PI\n INTEGER*4 DAY_OF_YEAR, DAYS_IN_YEAR\n\t\t\t\t\t\t\t\t\t\t\n GAMMA = 2*PI*(DAY_OF_YEAR-1)/DBLE(DAYS_IN_YEAR)\n SOLAR_ELLIPSE_FN = 1.00011+0.034211*COS(GAMMA) +\n 1 0.00128*SIN(GAMMA)+0.000719*COS(2*GAMMA) + 0.000077*SIN(2*GAMMA)\nc\nc//! Equation: 26\nc//! Description: Returns the scalar of the elliptical orbit of the \\\nc//! sun around the earth (approx +/- 3%; peak mid-summmer) \\\\\nc//! INPUTS: Day-number of the year; Number of days in the year;\\\\\nc//! mathematical constant, pi\nc//! Bibliography: S. Evans: SWELTER\nc\nc//! E: Ellipse = 1.00011+0.034211 cos(\\Gamma) + \\\nc//! 0.00128 sin(\\Gamma)+0.000719 cos(2 \\Gamma) + \\\nc//! 0.000077*sin(2 \\Gamma) \\\\\nc//! \\Gamma = {2 \\pi (DoY-1)} \\over{DinY}\nc\nc//! Variable: Ellipse\nc//! Description: Scalar of solar ellipse of the sun around the earth \nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: \\Gamma\nc//! Description: Intermediate variable\nc//! Units: none\nc//! Type: REAL*8\nc\nc//! Variable: DoY\nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable: DinY\nc//! Description: Total number of Days in year,(leap year=366)\nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable; \\pi\nc//! Description: the constant, pi, 3.12415...\nc//! Units: (radian)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION SOLAR_ELLIPSE2_FN(DAY_OF_YEAR) \n IMPLICIT NONE\n\nc** calculates the scalar of the elliptical orbit of the sun around \nc** the earth. About +/- 3%; Max in mud-summer\n INTEGER*4 DAY_OF_YEAR\n\t\t\t\t\t\t\t\t\t\t\n SOLAR_ELLIPSE2_FN = 1.033-0.066*sqrt(1.0-((DAY_OF_YEAR-183)**2)\n 1 /(183.**2) ) \nc\nc//! Equation: 27\nc//! Description: Returns the scalar of the elliptical orbit of the \\\nc//! sun around the earth (approx +/- 3%; peak mid-summmer) \\\\\nc//! INPUTS: Day-number of the year\nc//! Bibliography: \nc\nc//! E: Ellipse = 1.033-0.066 \\sqrt{{(1.0-((DoY-183)**2)} \\over \\\nc//! {(183.**2)} )} \nc\nc//! Variable: Ellipse\nc//! Description: Scalar of solar ellipse of the sun around the earth \nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: DoY\nc//! Description: Day of the year,(1st jan = 1, 31 dec=365 or 366) \nc//! Units: none \nc//! Type: Integer \nc\n RETURN\n END\n\n\n REAL*8 FUNCTION SOLAR_TIME_FN(GMT, LONGITUDE_RAD, \n 1 DAY_OF_YEAR, PI)\n IMPLICIT NONE\n\nc Routine calculates the local solar time from GMT. Applies only \nc to GMT based time.\n REAL*8 GMT, EQNTIME, CORR1, PI\n REAL*8 LONGITUDE_RAD\n INTEGER*4 DAY_OF_YEAR\n\nc correct time by equation of time and the longitudinal offset \n CORR1 = (279.575+0.986*DAY_OF_YEAR)*PI/180. \nc Equation of time: \n EQNTIME = (-104.7*SIN(CORR1) + 596.2*SIN(2*CORR1) + \n 1 4.3*SIN(3*CORR1) - 12.7*SIN(4*CORR1) - 429.3*COS(CORR1) - \n 2 2*COS(2*CORR1) + 19.3*COS(3*CORR1))/3600. \nc \n SOLAR_TIME_FN = GMT+EQNTIME+LONGITUDE_RAD*180.0/PI/15.0\nc\nc//! Equation: 28\nc//! Description: Converts from GMT (hours) to local solar time; \\\nc//! ie accounts for longitude and the equation of time. \\\\\nc//! INPUTS: Grenwich mean-time; longitude; day-number of the year;\\\nc//! mathematical constant, pi\nc//! Bibliography: Plaz & Grief (1996); Gronbeck 1999 (Web Pages)\nc\nc//! E: Sol_{time} = GMT + EQN_{time}+ {{180 Long } \\over{\\pi 15}}\nc\nc//! Variable: Sol_{time}\nc//! Description: Local solar time - corrected solar time (accounts \\\nc//! for longitude etc.)\nc//! Units: Hours\nc//! Type: REAL*8\nc//! SET\nc \nc//! Variable: GMT\nc//! Description: Time of day (Grenwich mean time)\nc//! Units: Hours\nc//! Type: REAL*8\nc\nc//! Variable: EQN_{time}\nc//! Description: Equation of time ; corrects for the slightly \\\nc//! elliptical orbit of the earth.\nc//! Units: Hours\nc//! Type: REAL*8\nc\nc//! Variable: Long \nc//! Description: Longitude of Site \nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: \\pi\nc//! Description: Mathematical constant, pi: 3.1415...\nc//! Units: (radian)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION GMT_FN(SOLAR_TIME, LONGITUDE_RAD, \n 1 DAY_OF_YEAR, PI)\n IMPLICIT NONE\n\nc Routine calculates the GMT from solar time. Applies only to GMT\nc based time.\n REAL*8 SOLAR_TIME, EQNTIME, CORR1, PI\n REAL*8 LONGITUDE_RAD\n INTEGER*4 DAY_OF_YEAR\n\nc correct time by equation of time and the longitudinal offset \n CORR1 = (279.575+0.986*DAY_OF_YEAR)*PI/180. \nc Equation of time: \n EQNTIME = (-104.7*SIN(CORR1) + 596.2*SIN(2*CORR1) + \n 1 4.3*SIN(3*CORR1) - 12.7*SIN(4*CORR1) - 429.3*COS(CORR1) - \n 2 2*COS(2*CORR1) + 19.3*COS(3*CORR1))/3600. \nc \n GMT_FN = SOLAR_TIME -(EQNTIME+LONGITUDE_RAD*180.0/PI/15.0)\nc\nc//! Equation: 29\nc//! Description: Converts from local solar time to GMT; \\\nc//! ie accounts for longitude and the equation of time. \\\\\nc//! INPUTS: Local Solar time; longitude; day-number of the year; Pi\nc//! Bibliography: Plaz & Grief (1996); Gronbeck 1999 (Web Pages)\nc\nc//! E: GMT = Sol_{time} -(EQN_{time} +{{180 Long } \\over{\\pi 15}})\nc\nc//! Variable: GMT\nc//! Description: Grenwich Mean Time of day (corrected for longitude \\\nc//! etc.)\nc//! Units: Hours\nc//! Type: REAL*8\nc//! SET\nc \nc//! Variable: Sol_{time}\nc//! Description: Local solar time - corrected solar time \nc//! Units: Hours\nc//! Type: REAL*8\nc\nc//! Variable: EQN_{time}\nc//! Description: Equation of time ; corrects for the slightly \\\nc//! elliptical orbit of the earth.\nc//! Units: Hours\nc//! Type: REAL*8\nc\nc//! Variable: Long \nc//! Description: Longitude of Site \nc//! Units: Radians\nc//! Type: REAL*8\nc\nc//! Variable: \\pi\nc//! Description: Mathematical constant, pi: 3.1415...\nc//! Units: (radian)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION TEMP_HOUR_FN(HOUR, TEMPMAX, TEMPMIN,PI)\n IMPLICIT NONE\n\nc** This function fits a sine curve over the day, ranging from \nc** TEMPMIN to TEMPMAX, with the maximum when HOUR=14 (ie 2pm)\n REAL*8 HOUR, TEMPMAX, TEMPMIN\n REAL*8 PI, TMEAN\nc\n TMEAN = ((TEMPMAX-TEMPMIN)/2.0)+TEMPMIN \n TEMP_HOUR_FN = SIN(((HOUR-2)/24.0*360-90)*PI/180.0)*\n 1 ((TEMPMAX-TEMPMIN)/2.0) + TMEAN\nc\nc//! Equation: 30\nc//! Description: returns the temperature at the time of day from \\\nc//! fitting a sine curve with peaks/troughs at the maximum and \\\nc//! minimum of the day. Peak assumed to be at time=14:00. Time is \\\nc//! assumed to be absolute ie no corrections for latitude are made.\\\\\nc//! INPUTS: Hour of the day; Maximum temperature of the day; \\\nc//! minimum temperature of the day. \nc//! Bibliography: none\nc\nc//! E: TEMP_{hour} = ({{T_{max}-T_{min}} \\over{2}} + T_{min}) + \\\nc//! sin( { ({{{360(hour-2)}\\over{24}} - 90} \\over {180} )} \\\nc//! ({{T_{max}-T_{min}} \\over{2}})\nc//!\nc//! Variable: TEMP_{hour}\nc//! Description: Temperature of day at time 'hour'\nc//! Units: Degrees celcius (usually)\nc//! Type: REAL*8 \nc//! SET \nc\nc//! Variable: T_{max}\nc//! Description: Maximum temperature of the day\nc//! Units: Degrees celcius (usually)\nc//! Type: REAL*8\nc\nc//! Variable: T_{min}\nc//! Description: Minumum temperature of the day\nc//! Units: Degrees celcius (usually)\nc//! Type: REAL*8\nc\nc//! Variable: \\pi \nc//! Description: Mathematical value 3.1415..\nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN\n END\n\n REAL*8 FUNCTION HUMIDITY_INST_FN(VP_UNSAT_BASE,\n 1 VP_SAT_NOW)\n IMPLICIT NONE\n\nc** Function calculates the humidity at any temperature\nc** Values at temperatures below freezing are doubtful.\n REAL*8 VP_UNSAT_BASE, VP_SAT_NOW\nc\n HUMIDITY_INST_FN = 100*VP_UNSAT_BASE/VP_SAT_NOW \nc//! Equation: 31\nc//! Description: Gets humidity at any time of the day eg 85%. \\\nc//! Assumes that vapour pressure is constant through the day. \\\nc//! usually we assume that VP is constant through the day and use\\\nc//! the '9am' values are used to get the vp; as temperature \\\nc//! changes, so will humidity. Beware if temperature < ZERO. \\\\\nc//! INPUTS: vapour pressure at base time; \\\nc//! Saturated VP at current temp.\nc//! Bibliography: LI-Cor Manual ??\nc//! \nc//! E: HUMID_{t} = {{100 VP_{unsat,base}} \\over{VP_{sat,t}} } \nc\nc//! Variable: HUMID_{t}\nc//! Description: humidity at temperature, t. Based on holding vapour \\\nc//! pressure constant through the day. Beware if temperature < ZERO \\\\\nc//! Units: Percentage\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: VP_{unsat,base}\nc//! Description: vapour pressure at reference time eg 9am\nc//! Units: Pascal (Pa)\nc//! Type: REAL*8\nc\nc//! Variable: VP_{sat,t}\nc//! Description: Saturated vapour pressure at temperature, t\nc//! Units: Pascal (Pa)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n SUBROUTINE RAIN_DAY_SUB(NO_RAIN_DAYS, RAIN_IN_MONTH, \n 1 DAYS_IN_MONTH, SEED1, SEED2, SEED3, RAIN)\n IMPLICIT NONE\n\n\n\nc** The routine simulates daily rainfall for all days in a month\nc** The typical number of rainy-days and average rainfall for the month \nc** Are the only specific Meteorology inputs. Returned is an array\nc** (1-dimensional; day) with the simulated rainfall for each day \nc** in it.\n REAL*8 RAIN(31)\n REAL*8 FRACT_WET, RAIN_DAY, RAIN_IN_MONTH, NO_RAIN_DAYS\n REAL*8 ZERO\n REAL*8 PROB_WET_WET, PROB_WET_DRY, GAMMA, MU\n INTEGER*4 DAYS_IN_MONTH, IDAY\n INTEGER*4 SEED1, SEED2, SEED3, IP, IP0\n REAL*8 RNDF, RAND01 , XLO, XHI, gamma2\n REAL*8 GAMMADIST_FN\n\nc\nc ** determine the proportion of the month with wet-days\n FRACT_WET = DBLE(NO_RAIN_DAYS)/DBLE(DAYS_IN_MONTH)\nc\nc** find the average rainfall per day with rainfall\n RAIN_DAY = RAIN_IN_MONTH/DBLE(NO_RAIN_DAYS)\nc\nc** find transitional probability of a wet-day following a dry-day\nc** of the month (Geng et al 1986)\n PROB_WET_DRY = 0.75*FRACT_WET\nc\nc** probability of wet-day following a wet-day (Geng et al 1986)\n PROB_WET_WET = 0.25+PROB_WET_DRY\nc\nc** Gamma distribution paramaters (Geng et al 1986) \nc GAMMA = -2.16+1.83*RAIN_DAY \n XLO = 0.0\n XHI=1.0\n\n RAND01 = RNDF(XLO,XHI, SEED1, SEED2, SEED3)\n GAMMA = 1.0\nc\nc** Mu paramaters (Geng et al 1986) \n gamma2 = gamma+(rand01-0.5)/2.0\n MU = RAIN_DAY/GAMMA2\nc\nc first of the month; the chances of it being wet is 'fract_wet'\nc get a random number proportional to the number of days in the month\n XLO = 0.0\n XHI=1.0\n RAND01 = RNDF(XLO,XHI, SEED1, SEED2, SEED3)\n DO 20 IDAY = 1, DAYS_IN_MONTH\n\tIF(IDAY.EQ.1) THEN\nc** is the random number<=rain_fract; if so then it rained yesterday\n\t IP0 = 0\n\t IF(RAND01.LE.FRACT_WET) THEN\n\t IP0 = 1 \n\t ENDIF\n\tENDIF\n\tRAIN(IDAY) = 0.0\n\tRAND01 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\tIF(IP0.EQ.1) THEN\nc** raining on day 0\n\t IF(RAND01-PROB_WET_WET .LE. 0) IP = 1\n\t IF(RAND01-PROB_WET_WET .GT. 0) IP = 0\n\tELSE ! IP0 = 0 ; its dry on day 0\n\t IF(RAND01-PROB_WET_DRY .LE. 0) IP = 1\n\t IF(RAND01-PROB_WET_DRY .GT. 0) IP = 0\n\tENDIF\n\tIP0 = IP\nc\n\tIF(IP.EQ.1) THEN ! Its raining today\n12 CONTINUE\n*12\t TR1 = EXP(-18.42*MU)\n\n*\t TR2 = EXP(-18.42*(1-MU))\n\n\nc RAND01 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\nc IF(RAND01 - TR1 .LE. 0) THEN\nc S1 = 0\nc ELSE\nc S1 = RAND01*EXP(1/MU)\nc ENDIF\nc RAND01 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\nc IF(RAND01 - TR2 .LE. 0) THEN\nc S2 = 0\nc ELSE\nc S2 = RAND01*EXP(1/(1-MU))\nc ENDIF\nc IF(S1+S2-1 .LE. 0) THEN\nc IF( (S1+S2).EQ.0 )THEN\nc Z = 0.0\nc ELSE\nc Z = S1/(S1+S2)\nc ENDIF\nc ELSE\nc FLAG = 1\nc ENDIF\nc IF(FLAG.EQ.1) GOTO 30\nc\nc RAND01 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\nc RAIN(IDAY) = -Z*LOG(RAND01)*GAMMA\n\t ZERO = 0.0\n\nC Changed GAMMA to GAMMA2 14/12/01 Paul Henshall.\n \n \t RAIN(IDAY)=GAMMADIST_FN(zero,MU,GAMMA2,SEED1,SEED2,SEED3)\n if(rain(iday).gt.rain_day*5)goto 12\n\tENDIF\n20 CONTINUE\nc\nc//! Equation: 32\nc//! Description: The routine simulates daily rainfall for all days in \\\nc//! a month. The typical number of rainy-days and average rainfall \\\nc//! for the month are the only specific Meteorology inputs. Returned \\\nc//! is an array (1-dimensional; day) with the simulated \\\nc//! rainfall for each day in it. Although the routine uses \\\nc//! Markov-chain principles, the start of each month is INDEPENDENT \\\nc//! of what the conditions were on the last day of the previous \\\nc//! month. \\\\\nc//! The routine calls a random-number gernerator (RNDF) which \\\nc//! returns numbers between Xmin and Xmax (in this case 0,1) using \\\nc//! the 3 seeds \\\\\nc//! INPUTS: Number of rainy days in the month; Average rainfall of \\\nc//! the month; number of days in the month; 3 seeds \\\nc//! for random number generation\\\\\nc//! OUTPUT: array (dimension:31), with rainfall for each day\nc//! Bibliography: S.Evans (SWELTER)\nc\nc//! Case: Day_{wet,dry}^{i} = 0\nc//! E: Rain_{day}^{i} = 0.0 \\\\\nc//! \\\\\nc//! Case: Day_{wet,dry}^{i} = 1 \\\\\nc//! \\\\\nc//! E: Rain_{day}^{i} = Z \\gamma log_{e} (Rnd_{j1,j2,j3}) \\\\\nc//! \\gamma = -2.16+1.83 Rain_{day,mean} \\\\\nc//! \\\\\nc//! Case: S_{1} + S_{2} -1 <= 0 \nc//! E: Z = { {{S_{1}} \\over{S_{1}+S_{2}} } \\\\\nc//! \\\\\nc//! Case: Rnd_{j1,j2,j3} - Tr_{1} <= 0\nc//! E: S_{1} = 0\nc//! Case: Rnd_{j1,j2,j3} - Tr_{1} > 0\nc//! E: S_{1} = Rnd_{j1,j2,j3} exp(1/\\mu) \\\\\nc//! \\\\\nc//! Case: Rnd_{j1,j2,j3} - Tr_{2} <= 0\nc//! E: S_{2} = 0\nc//! Case: Rnd_{j1,j2,j3} - Tr_{2} > 0\nc//! E: S_{2} = Rnd_{j1,j2,j3} exp(1/(1-\\mu)) \\\\\nc//! \\\\\nc//! Case: S_{1} + S_{2} -1 > 0\nc//! E: re-generate S_{1} and S_{2} \\\\\nc//! \\\\ \nc//! Tr_{1} = {exp(-18.42)}\\over{\\mu} \\\\\nc//! Tr_{2} = {exp(-18.42)}\\over{(1-mu)} \\\\\nc//! \\mu = {{Rain_{day,mean}} \\over{\\gamma}} \\\\\nc//! \\\\\nc//! Case: Day_{wet,dry}^{i-1} = 1 \\\\\nc//! \\\\\nc//! Case: Rnd_{j1,j2,j3} - Prob_{wet,wet} <= 0\nc//! E: Day_{wet,dry}^{i} = 1\nc//! Case: Rnd - Prob_{wet,wet} > 0\nc//! E: Day_{wet,dry}^{i} = 0 \\\\\nc//! \\\\\nc//! Case: Day_{wet,dry}^{i-1} = 0 \\\\\nc//! \\\\\nc//! Case: Rnd_{j1,j2,j3} - Prob_{wet,dry} <= 0\nc//! E: Day_{wet,dry}^{i} = 1 \nc//! Case: Rnd_{j1,j2,j3} - Prob_{wet,dry} > 0 \nc//! E: Day_{wet,dry}^{i} = 0 \\\\\nc//! \\\\\nc//! Prob_{wet,wet} = 0.25+Prob{wet,dry} \\\\\nc//! Prob_{wet,dry} = { {0.75 N_{rain days}} \\over{DinM} }\nc\nc//! Variable: Rain_{day}^{i}\nc//! Description: Predicted daily rainfall on day of month, i\nc//! Units: mm\nc//! Type: REAL*8 array (12,31)\nc//! SET\nc\nc//! Variable: Rain_{day,mean}\nc//! Description: Mean daily rainfall for the month\nc//! Units: mm/day\nc//! Type: REAL*8\nc\nc//! Variable: Rnd_{j1,j2,j3)\nc//! Description: Random number generated between 0 and 1\nc//! Units: none\nc//! Type: REAL*8\nc\nc//! Variable: j1\nc//! Description: Seed for random number generator; changed on return\nc//! Units: none\nc//! Type: Integer\nc\nc//! Variable: j2\nc//! Description: Seed for random number generator; changed on return\nc//! Units: none\nc//! Type: Integer\nc\nc//! Variable: j3\nc//! Description: Seed for random number generator; changed on return\nc//! Units: none\nc//! Type: Integer\nc\nc//! Variable: DinM\nc//! Description: Number of days in the month\nc//! Units: none\nc//! Type: Integer\nc\n RETURN\n END\n\n \n SUBROUTINE RAIN_DURATION_SUB(RAIN, RAIN_DURATION, RAIN_INTENSITY, \n 1 DAYS_IN_MONTH)\n IMPLICIT NONE\n\nc** This routine estimates the duration of rain on each day for a month\nc** Accuracy is suspect.\n REAL*8 RAIN(31) , RAIN_DURATION(31), RAIN_INTENSITY(31)\n REAL*8 RAIN_LIM(10), PRANGE, DUR(10)\n INTEGER*4 DAYS_IN_MONTH, IDAY\n INTEGER*4 N(10), RANGE\nc\n RAIN_LIM(1) = 0\n RAIN_LIM(2) = 5\n RAIN_LIM(3) = 10\n RAIN_LIM(4) = 15\n RAIN_LIM(5) = 20\n RAIN_LIM(6) = 25\n RAIN_LIM(7) = 50\n RAIN_LIM(8) = 75\n RAIN_LIM(9) = 100\n DO RANGE = 1,10\n N(RANGE) = 0\n ENDDO\nc\n DO 60 IDAY = 1, DAYS_IN_MONTH\n\tDO 70 RANGE = 1, 8,1\n\t IF( (RAIN(IDAY).GT.RAIN_LIM(RANGE)) .AND. \n 1 (RAIN(IDAY).LE.RAIN_LIM(RANGE+1)) ) THEN\n\t N(RANGE) = N(RANGE)+1\n\t ENDIF\n70 CONTINUE\n60 CONTINUE\nc \n DO 80 RANGE=1, 8, 1\n\tPRANGE = (RAIN_LIM(RANGE+1) - RAIN_LIM(RANGE)) / 25.4\n\tDUR(RANGE) = N(RANGE)/ (1.39*((PRANGE+0.1)** (-3.55)))\n80 CONTINUE\nc\n DO 90 IDAY = 1, DAYS_IN_MONTH\n\tRAIN_DURATION(IDAY) = 0.0\n\tRAIN_INTENSITY(IDAY) = 0.0\n\tIF(RAIN(IDAY).GT.0) THEN\n\t DO 100 RANGE =1,8,1\n\t IF( (RAIN(IDAY).GT.RAIN_LIM(RANGE)) .AND. \n 1 (RAIN(IDAY).LE.RAIN_LIM(RANGE+1)) ) THEN\n\t PRANGE = (RAIN_LIM(RANGE+1) - RAIN_LIM(RANGE)) \n\t RAIN_DURATION(IDAY) = DUR(RANGE)*RAIN(IDAY)/\n 1 PRANGE*60\n\t ENDIF\n100 CONTINUE\n\tRAIN_INTENSITY(IDAY) = RAIN(IDAY)/(RAIN_DURATION(IDAY)/60.0)\n\tENDIF\n\n90 CONTINUE\nc\nc//! Equation: 33\nc//! Description: This routine takes a months-worth of daily rainfall \\\nc//! data and calculates the duration of each event and intensity of\\\nc//! each event. Only one Event occurs each day. Accuracy seems \\\\\nc//! dubious. \\\\\nc//! INPUTS: Daily rainfall (array 31); Duaration of daily \\\nc//! rainfall [OUTPUT], (array 31); intensity of rainfall [OUTPUT]\\\nc//! ,(array 31); number of days in the month\nc//! Bibliography: S. Evans (SWELTER)\nc\nc//! Case: no rain\nc//! E: Rain_{dur}_{i} = 0.0\nc//! Case: Rainfall\nc//! E: Rain_{dur}_{i} = {{60 Rain_{dur:c} Rain_{day}_{i}} \\\\\nc//! \\over {Range_{c}}} \\\\\nc//! Range_{c} = Rainfall category range: x y :\\\\\nc//! [<5, 10, 15, 20, 25, 50, 75, 100] mm \\\\\nc//! \\\\\nc//! Rain_{dur:c}={ {\\sum_{i=1}^{DinM} Occurences of Rain_{day}_{i} \\\\\nc//! within rainfall category c} \\over {1.39 \\\\\nc//! ((Range_{c}/25.4 + 0.1)^{-3.55})} } \\\\\nc//! \\\\\nc//! Rain_{inten} = Rain_{day}^{i}/(Rain_{dur}^{i}/60.0)\nc//!\nc\nc//! Variable: Rain_{dur}_{i}\nc//! Description: Duration of rainfall on day of month, i\nc//! Units: minutes\nc//! Type: REAL*8 array (31)\nc//! SET\nc\nc//! Variable: Rain_{inten}_{i}\nc//! Description: Rainfall intensity on day of month, i\nc//! Units: mm /hour\nc//! Type: REAL*8\n\nc//! Variable: Rain_{day}_{i}\nc//! Description: Rainfall on day of month, i\nc//! Units: mm \nc//! Type: REAL*8\n\nc//! Variable: DinM\nc//! Description: Number of days in the month\nc//! Units: none\nc//! Type: Integer\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RNDF(XLO, XHI,J1, J2, J3)\n IMPLICIT NONE\n\nc** This random number routine w is from Brian Wichman and David Hill\nc** (BYTE, March 1987, page 127-128). Apparently the cycle length is\nc** about 6.95E12. Original reference: Wichmann & Hill, App stats (1982) \nc** 31(2) pp 188-190 with modification: A Mcleod, App stats (1985) \nc** 34(2) pp 198-200 \nc\n INTEGER*4 J1, J2, J3 \n REAL*8 R,XLO,XHI\nc \n IF(XLO.LT.XHI)THEN \n\tJ1=171*MOD(J1,177)-2*(J1/177) \n\tIF(J1.LT.0) J1 = J1+30269 \nc \n\tJ2=172*MOD(J2,176)-35*(J2/176) \n\tIF(J2.LT.0)J2=J2+30307 \nc \n\tJ3=170*MOD(J3,178)-63*(J3/178) \n IF(J3.LT.0) J3 = J3+30323 \nc \n\tR=DBLE(J1)/30269.0D0+DBLE(J2)/30307.0d0+DBLE(J3)/30323.0D0 \nc** modification re: A McLeod (1985) app. stats 34(2) 198-200 \nc** returns out of loops for efficiency - otherwise it was just \nC** a question of scaling. \n\tIF(R.GT.0) THEN \n\t RNDF=(R-INT(R))*(XHI-XLO)+XLO \n\t RETURN \n\tENDIF \n\tR=DMOD(DBLE(FLOAT(J1))/30269.0D0 + DBLE(FLOAT(J2))/30307.0D0 + \n 1 DBLE(FLOAT(J3))/30323.0D0, 1.0D0) \n\tIF(R.GE.1.0) R=0.999999 \n\tRNDF=(R-INT(R))*(XHI-XLO)+XLO \n\tRETURN \n ENDIF \nc \n RNDF=XLO \nc\nc//! Equation: 34\nc//! Description: Random number generator: uses 3 seeds and returns \\\nc//! changed seeds and a random number between Xlo and Xhi\\\\\nc//! INPUTS: Lowest value of random number; highest value of random \\\nc//! number; 3 seeds\nc//! Bibliography: Wichmann & Hill (1882), App stats 31(2) pp188-190; \\\nc//! A McLeod (1985) app. stats 34(2) pp98-200\nc\nc//! Case: R > 0\nc//! E: Rnd_{j1,j2,j3}=(R-INT(R))*(X_{hi}-X_{lo})+X_{lo}\nc//! Case: R<= 0\nc//! E: RNDF=(R1-INT(R1))*(X_{hi}-X_{lo})+X_{lo} \\\\\nc//! \\\\\nc//! E: R = j1/30269 + j2/30307 + j3/30323 \\\\\nc//! \\\\\nc//! E: R1 = MAX(0.999999, MOD(S_{1}/30269 + S_{2}/30307 + \\\nc//! S_{3}/30323.0D0, 1.0) \\\\\nc//! \\\\\nc//! E: j1 = 171 MOD(j1,177)-2(j}/177) \\\\\nc//! IF(j1 < 0 ; j1 = j1 + 30269 \\\\\nc//! \\\\\nc//! E: j2 = 172 MOD(j2,176)-35(j2/176) \\\\\nc//! IF(j2 < 0 ; j2 = j2 + 30307 \\\\\nc//! \\\\\nc//! E: j3 = 170 MOD(j3,178)-63(j3/178) \\\\\nc//! IF(j3 < 0 ; j3 = j3 + 30323 \nc \nc//! Variable: Rnd_{j1,j2,j3}\nc//! Description: Returned random number\nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: j1\nc//! Description: Seed for random number generation changed on exit\nc//! Units: none\nc//! Type: Integer\nc//! SET\nc\nc//! Variable: j2\nc//! Description: Seed for random number generation changed on exit\nc//! Units: none\nc//! Type: Integer\nc//! SET\nc\nc//! Variable: j3\nc//! Description: Seed for random number generation changed on exit\nc//! Units: none\nc//! Type: Integer\nc//! SET\nc\nc//! Variable: X_{lo}\nc//! Description: lowest possible value of random number\nc//! Units: none\nc//! Type: REAL*8\nc\nc//! Variable: X_{hi}\nc//! Description: highest possible value of random number\nc//! Units: none\nc//! Type: REAL*8\nc\n RETURN \n END\n\n\n REAL*8 FUNCTION TRANS_PROP_DAY_FN(RAD_ET_DAY, \n 1 RAD_TERRA_SW_DAY)\n IMPLICIT NONE\n\nc** Evaluates the total trasmission proportion (coefficient) for the day\n REAL*8 RAD_TERRA_SW_DAY\n REAL*8 RAD_ET_DAY\nc\n TRANS_PROP_DAY_FN = RAD_TERRA_SW_DAY/RAD_ET_DAY\nc\nc//! Equation: 35 \nc//! Description: Works out the proportion of Extra-terrestrial \\\nc//! radiation that arrives on the earth's surface as short-wave \\\nc//! in a day \\\\\nc//! INPUTS: Daily short-wave radiation on earth's surface; daily \\\nc//! Extra-terrestrial radiation.\nc//! Bibliography: S. Evans (SWELTER); Liu & Jordan (1960) Solar Energy \\\nc//! 4 pp1-19.\nc\nc//! E: T_{sw} = {RAD_{terra, sw} /over{RAD_{et}}}\nc\nc//! Variable: T_{sw}\nc//! Description: proportion of Extra-terrestrial radiation that \\\nc//! arrives on the earth's surface as short-wave.\nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{terra,sw}\nc//! Description: Terrestrial short-wave radiation on a horizonatal \\\nc//! plane for the given latitude and day.\nc//! Units: W/m2/d\nc//! Type: REAL*8\nc \nc//! Variable: RAD_{et} \nc//! Description: Extra-Terrestrial radiation above the atmosphere \\\nc//! for the given latitude and day.\nc//! Units: W/m2/d\nc//! Type: REAL*8 \nc\n RETURN\n END\n\n REAL*8 FUNCTION ANGSTROM_BETA_FN(LATITUDE_RAD)\n IMPLICIT NONE\n\nc** finds the Angstrom turbidity factor (the max clear-sky atmospheric\nc** transmittance characteristics at the latitude\n REAL*8 LATITUDE_RAD\nc\n ANGSTROM_BETA_FN = 0.682 - 0.3183*(1-1.3614*COS(LATITUDE_RAD))\nc\nc//! Equation: 36\nc//! Description: Caculation of the Angstrom beta function value: A \\\nc//! turbidity factor for the maximum clear-sky transmittance \\\nc//! characteristics at a given latitude. \\\\\nc//! INPUTS: Latitude\nc//! Bibliography: Nikolov & Zeller (1992) Ecological Modelling \\\nc//! 61:149-168; Gueymard (1989) Agric & Forest Met 45:215-229\nc\nc//! E: \\beta = 0.682 - 0.3183*(1-1.3614*cos(Lat))\nc\nc//! Variable: \\beta\nc//! Description: Angstrom tubidity factor: max clear sky transmittance\nc//! Units: none \nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: Lat\nc//! Description: Latitude of site (in radians) \nc//! Units: radians \nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION DIFFPROP_DAY2_FN(TRANS_PROP_DAY,\n 1 BETA)\n IMPLICIT NONE\n\nc**Estimates the proportion of terrestrial radiation that is diffuse\n REAL*8 TRANS_PROP_DAY, BETA\nc\n DIFFPROP_DAY2_FN = TRANS_PROP_DAY*(1-exp((-0.6*(1-BETA)/\n 1 TRANS_PROP_DAY) / (BETA-0.4)) )\nc\nc//! Equation: 37\nc//! Description: The proportion of light reaching the ground that \\\nc//! is made up of diffuse component \\\\\nc//! INPUTS: Daily extra-terrestrial radiation; Daily terrestrial \\\nc//! radiation; Angstrom beta value\nc//! Bibliography: S Evans (SWELTER); Bristow & Campbell (1985) Agric \\\nc//! & Forest Met 35:123-131; Becker & Weingarten (1991) Agric & \\\nc//! Forest Met 53:347-353\nc\nc//! E: Diff_{prop} = Tran(1-exp{({{-0.6(1-\\beta)} \\over{Tran}} \\\nc//! \\over{\\beta-0.4})}\nc\nc//! Variable: Diff_{prop} \nc//! Description: Proportion of daily terrestrial radiation that is \\\nc//! diffuse \\\\ \nc//! INPUTS: Extra-terrestrial daily radiation; Terrestrial daily \\\nc//! radiation \nc//! Units: none (Ratio) \nc//! Type: REAL*8 \nc//! SET \nc \nc//! Variable: Tran \nc//! Description: Proportion of Terrestrial radiation to \\\nc//! Extra-terrestrial radiation \nc//! Units: none (Ratio) \nc//! Type: REAL*8 \nc \nc//! Variable: \\beta\nc//! Description: Angstrom tubidity factor: max clear sky transmittance\nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RAD_TERRA_INST_FN(\n 1 DAWN, DUSK, DAYLENGTH, HOUR, RAD_TERRA_DAY, PI) \n IMPLICIT NONE\n\nc** calculate solar radiation for at any instant in time \nc** Assume sine wave with maximum at noon so ideally use local solar time\n REAL*8 RAD_TERRA_DAY\n REAL*8 DAWN, DUSK, DAYLENGTH, HOUR, SUNTIME\n REAL*8 PI\nc\nc**Give zero values for radiation at night otherwise set radiation\nc\n IF(HOUR .LT. DAWN .OR. (HOUR .GT. DUSK)) THEN\n\t RAD_TERRA_INST_FN = 0.0\n ELSE\nc** Sinusoidal function for hourly radiation from daily total \n\tSUNTIME = HOUR - DAWN\n\tRAD_TERRA_INST_FN = RAD_TERRA_DAY*PI/(2*DAYLENGTH)*\n 1 SIN(PI/DAYLENGTH*SUNTIME)/3600.0 \n ENDIF\nc\nc//! Equation: 38\nc//! Description: Fit a sine curve over the day - with peak at noon \\\nc//! (so local solar time is best) and periodicity over the \\\nc//! daylength \\\\\nc//! INPUTS: Latitude; Time of dawn; Time of dusk; Daylength; \\\nc//! Time of day; Daily terrestrial radiation ; Pi\nc//! Bibliography: Forest-GROWTH/FLUX; Meastro\nc\nc//! Case: Night\nc//! E: RAD_{now} = 0.0\nc//! Case: Dawn <= hour <= Dusk\nc//! E: RAD_{now} = {{RAD_{terra, day} \\pi sin(\\pi/(DAYL T)} \\\nc//! \\over{(2 DAYL 3600)}}\nc\nc//! Variable: RAD_{now}\nc//! Description: terrestrial radiation at any point in time; attained \\\nc//! from fitting a sine curve between dawn and dusk, peak at noon \\\nc//! using the daily radiation. Local solar times should be used\nc//! Units: W/m^{2} (shortwave radiation)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: Dawn\nc//! Description: Time of sunrise \nc//! Units: Hour\nc//! Type: REAL*8\nc\nc//! Variable: Dusk\nc//! Description: Time of sunset \nc//! Units: Hour\nc//! Type: REAL*8\nc\nc//! Variable: RAD_{terra, day}\nc//! Description: Daily terrestrial radiation \nc//! Units: W/m^{2}/day\nc//! Type: REAL*8\nc\nc//! Variable: DAYL\nc//! Description: Daylength \nc//! Units: Hours\nc//! Type: REAL*8\nc\nc//! Variable: hour\nc//! Description: Hour of the day - GMT base\nc//! Units: hour\nc//! Type: REAL*8\nc\n RETURN \n END \n\n \n REAL*8 FUNCTION WINDSPEED_INST_FN(WIND_RUN_DAY, HOUR)\n IMPLICIT NONE\n\nc** calculates windspeed at any point in time from a daily run of\nc** wind. This is based on a regression to get the daily max and \nc** min windspeed from the run of wind. Winspeed is assumed to be \nc** maximum at 14:00, and changes linearly about that\n REAL*8 WIND_RUN_DAY, HOUR\n REAL*8 WSMIN, WSMINCONST, WSMINCOEFF\n REAL*8 WSMAX, WSMAXCONST, WSMAXCOEFF\nc\nc ** this is parmaterised from Alice -Holt 1999: Regressing \nc** Run Vs WSMIN gives the coeffs: 0.0075x -0.3181, r2=0.7559\nc** Run vs WSMAX gives the coeffs, 0.0142x +0.6976, r2=0.8241\n WSMINCONST = -0.3181 ! -0.2253\n WSMINCOEFF = 0.0075 ! 0.0391\n WSMAXCONST = 0.6976 ! 0.2822\n WSMAXCOEFF = 0.0142 ! 0.0444\n WSMIN=MAX(0.0d0,WIND_RUN_DAY*WSMINCOEFF+WSMINCONST) \n WSMAX=MAX(0.0d0,WIND_RUN_DAY*WSMAXCOEFF+WSMAXCONST)\nc\n IF(HOUR.LE.13.0) THEN \n\tWINDSPEED_INST_FN = MAX(0.1d0,WSMIN+(WSMAX-WSMIN)/13.*(HOUR-1))\n ELSE \n\tWINDSPEED_INST_FN = MAX(0.1d0,WSMAX-(WSMAX-WSMIN)/11.*(HOUR-13))\n ENDIF\nc\nc//! Equation: 39\nc//! Description: Approximates wind-speed at any time of the day \\\nc//! from the daily run of wind. \\\\\nc//! INPUTS: Daily run of wind; Time of day\nc//! Bibliography: none ( M Broadmeadow: developed from regression at \\\nc//! the Straits)\nc\nc//! Case: Hour <=13\nc//! E: Wind_{now} = max(0.1, Wind_{min}+(Wind_{max}-Wind_{min}) \\\nc//! (Hour-1)/13)\nc//! Case: Hour >13\nc//! E: Wind_{now} = max(0.1, Wind_{max}+(Wind_{max}-Wind_{min}) \\\nc//! (Hour-13)/11) \\\\\nc//! \\\\\nc//! Wind_{max} = Wind_{run} WS_{max,1} + WS_{max,2} \\\\\nc//! \\\\\nc//! Wind_{min} = Wind_{run} WS_{min,1} + WS_{min,2} \nc\nc//! Variable: Wind_{now}\nc//! Description: Windspeeds at current time\nc//! Units: m/s\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: WS_{max,1}\nc//! Description: Linear regression coefficient of max windspeed Vs \\\nc//! run of wind\nc//! Units: Km/g / m/s\nc//! Type: REAL*8\nc\nc//! Variable: WS_{max,2}\nc//! Description: Linear regression constant of max windspeed Vs \\\nc//! run of wind\nc//! Units: m/s\nc//! Type: REAL*8\nc\nc//! Variable: WS_{min,1}\nc//! Description: Linear regression coefficient of min windspeed Vs \\\nc//! run of wind\nc//! Units: Km/g / m/s\nc//! Type: REAL*8\nc\nc//! Variable: WS_{min,2}\nc//! Description: Linear regression constant of min windspeed Vs \\\nc//! run of wind\nc//! Units: m/s\nc//! Type: REAL*8\nc\nc//! Variable: Wind_{run}\nc//! Description: Daily run of wind\nc//! Units: Km/d\nc//! Type: REAL*8\nc\nc//! Variable: Hour\nc//! Description: Hour of the day - GMT base\nc//! Units: hour\nc//! Type: REAL*8\nc\n RETURN \n END \n\n \n REAL*8 FUNCTION RAD_TERRA_SUNDAY_FN(DAYLENGTH,SUN_HOURS,\n 1 RAD_ET_DAY) \n IMPLICIT NONE\n\nc** Predicts terrestrial radiation from sun-shine hours\nc** Rad_terra= a + b*Sun/daylen + c*(Sun/daylen)**2 + d*(Sun/DAYLEN)**3\nc** Other conversions eg Angstom 1924; Collingbourne 1976 use a linear \nc** Function; ie 2 params\n REAL*8 CONST, COEFFA, COEFFB, COEFFC, SRATIO\n REAL*8 DAYLENGTH, PRED_GRATIO\n REAL*8 RAD_ET_DAY, SUN_HOURS\nc \n CONST = 0.17262 \n COEFFA =0.9901 \n COEFFB =-1.043 \n COEFFC = 0.585 \nc \n\t SRATIO = SUN_HOURS/DAYLENGTH\n\t IF(SRATIO.GT.1) THEN \n\t SRATIO = 1 \n\t ENDIF \nc\n\t PRED_GRATIO = CONST + COEFFA*SRATIO + COEFFB*SRATIO**2 + \n + COEFFC*SRATIO**3 \n\t RAD_TERRA_SUNDAY_FN = RAD_ET_DAY*PRED_GRATIO !J/day\nc\nc//! Equation: 40\nc//! Description: Method of predicting terrestrial radiation from \\\nc//! sun-shine hours. Note often only \\alpha and \\beta are used in \\\nc//! the equation below: \\\\\nc//! INPUTS: Daylength; Sunhine-hours; Daily Extra-terrestrial \\\nc//! radiation; Mathematical constant, pi\nc//! Bibliography: Angstrom (1924) Q.J. R.met. Soc 50,121-5; \\\nc//! Collingbourne (1976) In: The Climate of the British Isles. \\\nc//! eds TJ Chandler & S Gregory, Longman, pp74-95; Randle (1997) \\\nc//! FC Internal report\nc\nc//! E: RAD_{terra,day} = RAD_{et,day} (\\alpha + \\beta*S/S_{0} + \\\nc//! \\gamma (S/S_{0})^{2} + \\delta (S/S_{0})^{2} )\nc\nc//! Variable: RAD_{terra,day}\nc//! Description: Daily terrestrial radiation predicted from \\\nc//! sun-shine hours\nc//! Units: W/m^{2}/d\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{et,day}\nc//! Description: Daily extra-terrestrial radiation\nc//! Units: W/m^{2}/d\nc//! Type: REAL*8\nc\nc//! Variable: S\nc//! Description: Sun-shine hours in the day\nc//! Units: hours \nc//! Type: REAL*8\nc\nc//! Variable: S_{0}\nc//! Description: Daylength\nc//! Units: hours \nc//! Type: REAL*8\nc\nc//! Variable: /alpha\nc//! Description: Constant of regression of S/S_{0} and Rad_{et,day}. \\\nc//! If linear regression this is 'Angstrom \\alpha'\nc//! Units: W/m^{2}/d \nc//! Type: REAL*8\nc\nc//! Variable: /beta \nc//! Description: First order coefficient of regression of S/S_{0} \\\nc//! and Rad_{et,day}. If linear regression this is 'Angstrom \\beta'\nc//! Units: W/m^{2}/d \nc//! Type: REAL*8\nc\nc//! Variable: /gamma\nc//! Description: Second order coefficient of regression of S/S_{0}. \\\nc//! and Rad_{et,day}. If linear regression this is zero\nc//! Units: W/m^{2}/d \nc//! Type: REAL*8\nc\nc//! Variable: /delta \nc//! Description: Constant of regression of S/S_{0} and Rad_{et,day}. \\\nc//! if linear regression this is zero\nc//! Units: W/m^{2}/d \nc//! Type: REAL*8\nc\nc//! Variable: \\pi\nc//! Description: Mathematical constant, pi\nc//! UNits: (Radian)\nc//! Type: REAL*8\nc\n RETURN \n END \n\n\n REAL*8 FUNCTION TEMP_AIR_AMPLITUDE_FN(TRANS_PROP_DAY,\n 1 A_SKY, ANGSTROM_BETA, C_SKY) \n IMPLICIT NONE\n\nc** determines apriximate air temperature amplitude (tmax- tmin) from\nc** transmitted radiation and some parameters\n REAL*8 TRANS_PROP_DAY\n REAL*8 A_SKY, ANGSTROM_BETA, C_SKY, DELTA\n\n DELTA = 1-TRANS_PROP_DAY/ANGSTROM_BETA\n IF(DELTA.LE.0) THEN \n\tTEMP_AIR_AMPLITUDE_FN = 0.0\n ELSE\n\tTEMP_AIR_AMPLITUDE_FN = (LOG(DELTA)/(-A_SKY))**(1/C_SKY)\n ENDIF\nc\nc//! Equation: 41\nc//! Description: Works out the daily temperature differecne amplitude \\\nc//! from the transmittance of radiation; if it is cloudy, then less \\\nc//! radiation gets through and there should be less temperature \\\nc//! variation \\\\\nc//! INPUTS: Proportion of Extra-terrestrial light reaching the \\\nc//! earth; Coefficient for maximum clear-sky transmittance; \\\nc//! Angstrom \\beta value; Coefficient of clear-sky transmittance \\\nc//! with amplitude temperature increase. \nc//! Bibliography: S Evans (SWELTER); Bristow & Campbell (1984) Agric \\\nc//! & Forest Met 31: 159-166\nc\nc//! Case: 1-{{T_{sw}} \\over{\\beta}} <=0\nc//! E: \\Delta T = 0.0\nc//! Case: 1-{{T_{sw}} \\over{\\beta}} > 0\nc//! E: \\Delta T = (Log_{e}(\\delta/(-A_{sky})) )^(1/C_{sky})\nc\nc//! Variable: \\Delta T\nc//! Description: Daily amplitude of temperature variation\nc//! Units: Degrees C (usually)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: T_{sw}\nc//! Description: proportion of Extra-terrestrial radiation that \\\nc//! arrives on the earth's surface as short-wave.\nc//! Units: none\nc//! Type: REAL*8\nc\nc//! Variable: \\beta\nc//! Description: Angstrom tubidity factor: max clear sky transmittance\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: A_{sky}\nc//! Description: Coefficient of maximum clear-sky transmittance \\\nc//! characteristics\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: C_{sky}\nc//! Description: Coefficient of maximum clear-sky transmittance \\\nc//! with \\Delta T increase\nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN\n END\n \n \n REAL*8 FUNCTION DIFF_PROP_HOUR_FN(DIFF_PROP_DAY, \n 1 SOL_ELEV)\n IMPLICIT NONE\n\nc** finds the proportion of idiifuse light at the earth's surface on\nc** an hourly basis (ie elevation should be calculated hour by hour\nc** and this feeds back the diffuse light proportion for this hour\n REAL*8 DIFF_PROP_DAY, R, K\n REAL*8 SOL_ELEV\nc\n R = 0.847-1.61*SIN(SOL_ELEV) + 1.04*(SIN(SOL_ELEV)**2)\n K = (1.47-R)/1.66 \n IF(DIFF_PROP_DAY.lt.0.22) then \n\t DIFF_PROP_HOUR_FN = 1.0 \n ELSE IF(DIFF_PROP_DAY.lt.0.35) then \n\t DIFF_PROP_HOUR_FN = 1-6.4*(DIFF_PROP_DAY-0.22)**2 \n ELSE IF(DIFF_PROP_DAY.lt.K) then \n\t DIFF_PROP_HOUR_FN = 1.47-1.66*DIFF_PROP_DAY\n ELSE \n\t DIFF_PROP_HOUR_FN = R \n ENDIF \nc\nc//! Equation: 42\nc//! Description: Finds the proportion of diffuse/total light at the \\\nc//! earth's surface on an hourly basis. Elevation should change \\\nc//! hour-by-hour. Usually used when hourly terrestrial radiation \\\nc//! levels are known. \\\\\nc//! INPUTS: Proportion of diffuse light (daily basis); \\\nc//! Solar elevation \nc//! Bibliography: Spitters Et al (1986), Agric & Forest Met \\\nc//! 38:217-229; de Jong (1980). \nc\nc//! Case: Diff_{prop} <= 0.22\nc//! E: Diff_{prop,h} = 1.0\nc//! Case: 0.22 < Diff_{prop} <= 0.35\nc//! E: Diff_{prop,h} = 1 - 6.4(Diff_{prop}-0.22)^{2}\nc//! Case: 0.35 < Diff_{prop} <= K \nc//! E: Diff_{prop,h} = 1.47 - 1.66 Diff_{prop}\nc//! Case: K < Diff_{prop} \nc//! E: Diff_{prop,h} = R \\\\\nc//! \\\\\nc//! E: K = (1.47-R)/1.66 \\\\\nc//! \\\\\nc//! E: R = 0.847-1.61 sin(\\beta)\nc\nc//! Variable: Diff_{prop,h} \nc//! Description: Proportion of hourly terrestrial radiation that is \\\nc//! diffuse at hour h \\\\\nc//! INPUTS: Proportion of daily radiation that is diffuse; Solar \\\nc//! elevation at hour, h\nc//! Units: none (Ratio) \nc//! Type: REAL*8 \nc//! SET\nc\nc//! Variable: Diff_{prop} \nc//! Description: Proportion of daily terrestrial radiation that is \\\nc//! diffuse \\\\\nc//! Units: none (Ratio) \nc//! Type: REAL*8 \nc \nc//! Variable: \\beta \nc//! Description: Solar elevarion at hour, h\nc//! Units: Radians\nc//! Type: REAL*8 \nc\n RETURN \n END \n\n\n REAL*8 FUNCTION TEMP_MAX_DAY_FN(TEMP_AIR_AMPLITUDE, \n 1 TEMP_DAY_MEAN)\n IMPLICIT NONE\n\nc** predicts max air temp from the mean temp and amplitude: based on \nc** tmean = (tmax-tmin)/2\n REAL*8 TEMP_AIR_AMPLITUDE\n REAL*8 TEMP_DAY_MEAN\nc\n TEMP_MAX_DAY_FN = TEMP_DAY_MEAN + (TEMP_AIR_AMPLITUDE)/2.0\nc\nc//! Equation: 43\nc//! Description: Derives maximum air temperature from the daily mean \\\nc//! and daily amplitude. Based on Tmean=(tmax-Tmin)/2 \\\\\nc//! INPUTS: Daily temperature variation amplitude; Daily mean \\\nc//! temperature\nc//! Bibliography: none\nc\nc//! E: T_{max} = T_{mean} + \\Delta T /2\nc\nc//! Variable: T_{max}\nc//! Description: Daily maximum temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc//! SET\nc\nc//! Variable: T_{mean}\nc//! Description: Daily mean temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: \\Delta T \nc//! Description: Daily temperature variation amplitude\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION TEMP_MIN_DAY_FN(TEMP_AIR_AMPLITUDE, \n 1 TEMP_DAY_MEAN)\n IMPLICIT NONE\n\nc** predicts min air temp from the mean temp and amplitude: based on \nc** tmean = (tmax-tmin)/2\n REAL*8 TEMP_AIR_AMPLITUDE\n REAL*8 TEMP_DAY_MEAN\nc\n TEMP_MIN_DAY_FN = TEMP_DAY_MEAN - (TEMP_AIR_AMPLITUDE)/2.0\nc\nc//! Equation: 44\nc//! Description: Derives minimum air temperature from the daily mean \\\nc//! and daily amplitude. Based on Tmean=(tmax-Tmin)/2 \\\\\nc//! INPUTS: Daily temperature variation amplitude; Daily mean \\\nc//! temperature\nc//! Bibliography: none\nc\nc//! E: T_{min} = T_{mean} + \\Delta T /2\nc\nc//! Variable: T_{min}\nc//! Description: Daily minimum temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc//! SET\nc\nc//! Variable: T_{mean}\nc//! Description: Daily mean temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: \\Delta T \nc//! Description: Daily temperature variation amplitude\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\n RETURN\n END\n\n REAL*8 FUNCTION TEMP_AIR_AMPLITUDE2_FN(TEMP_MAX_DAY,\n 1 TEMP_MIN_DAY)\n IMPLICIT NONE\n\nc** gets the daily temperature variation: ie. Tmax-Tmin\n REAL*8 TEMP_MAX_DAY\n REAL*8 TEMP_MIN_DAY \nc\n TEMP_AIR_AMPLITUDE2_FN = TEMP_MAX_DAY - TEMP_MIN_DAY\nc\nc//! Equation: 45\nc//! Description: Derives the daily temperature variation from the \\\nc//! maximum and minimums of the day \\\\\nc//! INPUTS: Temperature maximum; Temperature minimum\nc//! Bibliography: none\nc\nc//! E: \\Delta T = T_{max} - T_{min}\nc\nc//! Variable: \\Delta T\nc//! Description: Daily amplitude of temperature variation\nc//! Units: Degrees C (usually)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: T_{min}\nc//! Description: Daily minimum temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: T_{max}\nc//! Description: Maximum daily temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION TEMP_DAY_MEAN_FN(TEMP_MAX_DAY,\n 1 TEMP_MIN_DAY)\n IMPLICIT NONE\n\nc** calculates mean daily temperature based on (Tmin+Tmax)/2\n REAL*8 TEMP_MAX_DAY, TEMP_MIN_DAY\nc\n TEMP_DAY_MEAN_FN = (TEMP_MIN_DAY + TEMP_MAX_DAY)/2.0\nc\nc//! Equation: 46\nc//! Description: calculates Avrage daily temperature from the daily \\\nc//! minimum and maximum \\\\\nc//! INPUTS: Daily maximum temperature; Daily minimum temperature\nc//! Bibliography: none\nc\nc//! E: Temp_{mean} = (Temp_{min}+Temp_{max})/2.0\nc\nc//! Variable: T_{mean}\nc//! Description: Daily mean temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc//! SET\nc\nc//! Variable: T_{min}\nc//! Description: Daily minimum temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: T_{max}\nc//! Description: Maximum daily temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION TEMP_DAY_MEAN2_FN(TEMP_MEAN_MONTH,\n 1 TEMP_SD_MONTH, TEMP_AUTOCORR_MONTH, TEMP_YESTERDAY, IS1,\n 2 IS2, IS3, NORMSWITCH)\n \n IMPLICIT NONE\n EXTERNAL NORM_FROM_RAND_FN\n\n\nc \nc** calculates mean daily temperature from monthly values \n REAL*8 TEMP_MEAN_MONTH\n REAL*8 TEMP_SD_MONTH, TEMP_AUTOCORR_MONTH\n REAL*8 TEMP_YESTERDAY\n REAL*8 NORM, NORMMN, NORMSD\n REAL*8 NORM_FROM_RAND_FN\n INTEGER*4 IS1, IS2, IS3, NORMSWITCH\nC \nc** approximate a function to get a normal distribution, mean=0, sd=1\n NORMMN=0.0\n NORMSD = 1.0\n NORM=NORM_FROM_RAND_FN(NORMMN, NORMSD, IS1, IS2, IS3, NORMSWITCH)\nc\n TEMP_DAY_MEAN2_FN = TEMP_MEAN_MONTH + TEMP_AUTOCORR_MONTH*\n 1 (TEMP_YESTERDAY - TEMP_MEAN_MONTH) + TEMP_SD_MONTH*\n 2 NORM*( (1-(TEMP_AUTOCORR_MONTH)**2)**0.5)\nc\nc//! Equation: 47\nc//! Description: Calculates Average daily temperature from monthly \\\nc//! means and standard-deviations. Autocorrelation of 0.65 seems \\\nc//! to work if one isn't available. \\\\\nc//! INPUTS: Mean temperature of the month; Standard deviation \\\nc//! around the mean on a daily basis; Temperature \\\nc//! auto-correlation for each month; Mean temperature of the \\\nc//! previous day; 3 random number seeds.\nc//! Bibliography: S Evans (SWELTER); Haith, Tubbs & Pickering (1984) \\\nc//! Simulation of Pollution by soil erosion & soil nutirnt loss, \\\nc//! PUDOC, Wageningen\nc\nc//! E: Temp_{mean} = Temp_{mean,month} + \\rho_{T} (Temp_{day-1} - \\\nc//! Temp_{mean,month}) + \\sigma_{mT} N (1-\\sigma_{mT}^{2})^0.5) \\\\\nc//! \\\\\nc//! E: N = { Random, N(0,1) }\nc\nc//! Variable: Temp_{mean}\nc//! Description: Daily mean temperature\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc//! SET\nc\nc//! Variable: Temp_{mean,month}\nc//! Description: Mean daily temperature (monthly basis)\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: Temp_{day-1} \nc//! Description: Mean daily temperature of the previous day\nc//! Units: Degrees C (usually)\nc//! Type: Double precsion\nc\nc//! Variable: \\rho_{T}\nc//! Description: Observed first-order auto-correlation of mean \\\nc//! daily air temperature for each month\nc//! Units: none (day/day^{-1})\nc//! Type: Double precsion\nc\nc//! Variable: \\sigma_{mT}\nc//! Description: Standard deviation of daily air temperature about \\\nc//! the mean (monthly basis).\nc//! Units: Degrees C \nc//! Type: Double precsion\nc\nc//! Variable: R\nc//! Description: Random number between 0,1\nc//! Units: none\nc//! Type: Double precsion\nc\n RETURN\n END\n\n \n REAL*8 FUNCTION WIND_DAY_MEAN_FN(WIND_MONTH_MEAN, \n 1 WIND_SD_MONTH, WIND_AUTOCORR_MONTH, WIND_YESTERDAY, IS1, IS2, \n 2 IS3, NORMSWITCH)\n IMPLICIT NONE\n EXTERNAL NORM_FROM_RAND_FN\n\n\n\nc** Generates windspeed at a daily scale from monthly means, standard \nc** devaitions and autocorrelation (monthly)\n REAL*8 WIND_MONTH_MEAN, WIND_SD_MONTH\n REAL*8 WIND_AUTOCORR_MONTH, WIND_YESTERDAY\n REAL*8 NORM, NORMMN, NORMSD, NORM_FROM_RAND_FN\n INTEGER*4 IS1, IS2, IS3, NORMSWITCH\nc\n NORMMN = 0.0\n NORMSD =1.0\nc** approximate a function to get a normal distribution, mean=0, sd=1\n NORM = NORM_FROM_RAND_FN(NORMMN, NORMSD,IS1,IS2,IS3,NORMSWITCH)\nc\n WIND_DAY_MEAN_FN = WIND_MONTH_MEAN + WIND_AUTOCORR_MONTH*\n 1 (WIND_YESTERDAY - WIND_MONTH_MEAN) + WIND_SD_MONTH*\n 2 NORM*( (1-(WIND_AUTOCORR_MONTH)**2)**0.5)\n WIND_DAY_MEAN_FN = MAX(WIND_DAY_MEAN_FN, 0.1d0)\nc\nc//! Equation: 48\nc//! Description: Calculates Average daily windspeed from monthly \\\nc//! means and standard-deviations. Autocorrelation of 0.65 seems \\\nc//! to work if one isn't available. \\\\\nc//! INPUTS: Mean daily windspeed of the month; Standard deviation \\\nc//! around the mean on a daily basis; windspeed \\\nc//! auto-correlation for each month; Mean windspeed of the \\\nc//! previous day; 3 random number seeds.\nc//! Bibliography: S Evans (SWELTER); Haith, Tubbs & Pickering (1984) \\\nc//! Simulation of Pollution by soil erosion & soil nutirnt loss, \\\nc//! PUDOC, Wageningen\nc\nc//! E: Wind_{mean} = Wind_{mean,month} + \\rho_{W} (Wind_{day-1} - \\\nc//! Wind_{mean,month}) + \\sigma_{mW} N (1-\\sigma_{mW}^{2})^0.5) \\\\\nc//! \\\\\nc//! E: N = { Random, N(0,1) }\nc\nc//! Variable: Wind_{mean}\nc//! Description: Daily mean winsdpeed \nc//! Units: m/s \nc//! Type: Double precsion\nc//! SET\nc\nc//! Variable: Wind_{mean,month}\nc//! Description: Mean daily windspeed (monthly basis)\nc//! Units: m/s\nc//! Type: Double precsion\nc\nc//! Variable: Wind_{day-1} \nc//! Description: Mean daily windspeed of the previous day\nc//! Units: m/s\nc//! Type: Double precsion\nc\nc//! Variable: \\rho_{W}\nc//! Description: Observed first-order auto-correlation of mean \\\nc//! daily windspeed for each month\nc//! Units: none (day/day^{-1})\nc//! Type: Double precsion\nc\nc//! Variable: \\sigma_{mW}\nc//! Description: Standard deviation of daily windspeed about \\\nc//! the mean (monthly basis).\nc//! Units: m/s \nc//! Type: Double precsion\nc\nc//! Variable: R\nc//! Description: Random number between 0,1\nc//! Units: none\nc//! Type: Double precsion\nc\n RETURN\n END\n \n\ncc commented by Ghislain 30/06/03 because it does not compile... and I don't need it \nccc REAL*8 FUNCTION CLOUD_COVER_FN(VP_SAT,RAINFALL_DAY, RH,\nccc 1 is1, is2, is3, pmax) \nccc IMPLICIT NONE\nccc\nccc\nccc\ncccc** Cloudiness for the day\nccc REAL*8 VP_SAT, RAINFALL_DAY, RH, GAMMADIST_FN\nccc REAL*8 RNDF, xlo ,xhi, pmax, mock_rain,mu, gamma, zero\nccc integer*4 is1, is2, is3\ncccc\nccc CLOUD_COVER_FN = 10-1.155*SQRT(VP_SAT/MAX(RAINFALL_DAY,0.1))\ncccc CLOUD_COVER_FN = 10-2.5*SQRT(VP_SAT/MAX(RAINFALL_DAY,0.1))\nccc CLOUD_COVER_FN = MAX(CLOUD_COVER_FN, 0.0)/10.0\nccc if(RAINFALL_DAY.le.0.001) then\nccc mu = rh ! average rain on a wet day\nccc gamma = 1.0\nccc zero = 0.0\nccc mock_rain = GAMMADIST_FN(zero, mu, gamma, is1, is2, is3)\nccc CLOUD_COVER_FN = 10-2.5*SQRT(VP_SAT/MAX(mock_rain,0.1))\ncccc CLOUD_COVER_FN = 10-1.155*SQRT(VP_SAT/MAX(mock_rain,0.1))\nccc\nccc CLOUD_COVER_FN = MAX(CLOUD_COVER_FN, 0.0)/10.0\nccc CLOUD_COVER_FN=1*CLOUD_COVER_FN\nccc else ! when raining adjust\ncccc increase cloudiness - esp during summer when svp is high and raining\nccc CLOUD_COVER_FN=1*CLOUD_COVER_FN\nccc CLOUD_COVER_FN=min(1, (0.007*VP_SAT+0.995)*CLOUD_COVER_FN)\nccc endif\nccc \ncccc//! Equation: 49\ncccc//! Description: Proportion of the day that is cloudy \\\\\ncccc//! INPUTS: saturated vapour-pressure; daily rainfall\ncccc//! Bibliography: S Evans {SWELTER); Nikolov & Zeller (1992) \\\ncccc//! Ecological Modelling 61:149-168\ncccc\ncccc//! E: Cld = 10-1.155 {(VP_{sat}\\over{Rain})^0.5\ncccc\ncccc//! Variable: Cld\ncccc//! Description: Cloudiness of the day\ncccc//! Units: none (proportion)\ncccc//! Type: REAL*8\ncccc//! SET\ncccc\ncccc//! Variable: VP_{sat}\ncccc//! Description: Saturated vapour pressure\ncccc//! Units: Pa\ncccc//! Type: REAL*8\ncccc\ncccc//! Variable: Rain\ncccc//! Description: amount of rainfall on the day\ncccc//! Units: mm\ncccc//! Type: REAL*8\ncccc\nccc RETURN\nccc END\n\n\n INTEGER*4 FUNCTION DAYS_IN_MONTH_FN(MM, DAYSINYEAR)\n IMPLICIT NONE\n\n INTEGER*4 DAYSINYEAR, MM, LEAPSHIFT\nc** returns the day number of days in a month (allows for leap year).\nc\n\n\tLEAPSHIFT=DAYSINYEAR-365\n\tIF(MM.EQ.1) THEN \n\t DAYS_IN_MONTH_FN = 31 \n\tELSE IF(MM.EQ.2) THEN \n\t DAYS_IN_MONTH_FN = 28 + LEAPSHIFT \n\tELSE IF(MM.EQ.3) THEN \n\t DAYS_IN_MONTH_FN = 31\n\tELSE IF(MM.EQ.4) THEN \n\t DAYS_IN_MONTH_FN = 30\n\tELSE IF(MM.EQ.5) THEN\n\t DAYS_IN_MONTH_FN = 31\n\tELSE IF(MM.EQ.6) THEN \n\t DAYS_IN_MONTH_FN = 30\n\tELSE IF(MM.EQ.7) THEN \n\t DAYS_IN_MONTH_FN = 31\n\tELSE IF(MM.EQ.8) THEN \n\t DAYS_IN_MONTH_FN = 31\n\tELSE IF(MM.EQ.9) THEN \n\t DAYS_IN_MONTH_FN = 30\n\tELSE IF(MM.EQ.10) THEN \n\t DAYS_IN_MONTH_FN = 31\n\tELSE IF(MM.EQ.11) THEN \n\t DAYS_IN_MONTH_FN = 30\n\tELSE IF(MM.EQ.12) THEN\n\t DAYS_IN_MONTH_FN = 31\n\tELSE\n DAYS_IN_MONTH_FN = 0\n ENDIF\n\nc\nc//! Equation: 50\nc//! Description: finds the number of days in a month \\\\\nc//! INPUTS: Month of year (numeric); Number of days in the year\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: None \nc \nc//! Variable: DinM \nc//! Description: Number of days in the month \nc//! Units: none \nc//! SET\nc//! Type: Integer \nc\nc//! Variable: mm \nc//! Description: month number \nc//! Units: none \nc//! Type: Integer \nc\nc//! Variable: DinY \nc//! Description: Days in the year (allows for leap year)\nc//! Units: none \nc//! Type: Integer \nc\n RETURN \n END \n\n\n REAL*8 FUNCTION RADIAN_FROM_DEGREE_FN(DEGREES, PI)\n IMPLICIT NONE\n\nc** 360 degrees is 2*PI radians:\n REAL*8 DEGREES, PI\n\tRADIAN_FROM_DEGREE_FN = (2*PI*DEGREES)/360.0\nc\nc//! Equation: 51\nc//! Description: converts degrees to radians \\\\\nc//! INPUTS: Degrees (decimal); the mathematical constant, PI\nc//! Bibliography: No Specific reference to this function.\nc\nc//! E: RAD = 2 \\pi DEG \\over{260.0)\nc \nc//! Variable: RAD \nc//! Description: returned value: radian\nc//! Units: radian\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: \\pi \nc//! Description: mathematical constant, pi, 3.14115...\nc//! Units: radian\nc//! Type: REAL*8\nc\nc//! Variable: DEG \nc//! Description: number of degrees to be converted\nc//! Units: Degrees\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n SUBROUTINE NORTHEAST_TO_LATLONG_SUB(EASTING, NORTHING, LATITUDE,\n 1 LONGITUDE, PI)\n IMPLICIT NONE \n\nc** Uses the National Grid scale factors, true origins etc (after \nc** Airy (1830). These are not the same os the Irish National grid etc\nc** though the formaule are the same (just different values) \n REAL*8 NORTHING, EASTING, LATITUDE, LONGITUDE, F0\n REAL*8 P0, L0, N0, E0, A, B, PI\n REAL*8 P0_RAD, L0_RAD, R, ETASQ, V, PX, PXNEW, ESQ\n REAL*8 I7, I8, I9, I10, I11, I12, I12A , M,N\nc \nc set the constants for the OS36 UK national grid settings:\n A = 6377563.396 \n B = 6356256.910 \n F0 = 0.9996012717 \n P0 = 49.0 ! 49 deg N True origin\n L0 = -2.0 ! 2 deg W True origin\n E0 = 400000.0\n N0 = -100000.0\nc convert true origins to radians \n P0_RAD = P0*PI/180.0 \n L0_RAD = L0*PI/180.0 \nc\nc Eccentricity squared: \n ESQ = (A**2 - B**2)/(A**2) \nc Intermediates: \n N = (A-B)/(A+B) \nc \nc PX new is the estimate for the the Latitude\n PX = ((NORTHING-N0)/(A*F0))+P0_RAD \nc Initialise M for first iteration, then continue iterations until\nc desired accuracy is met (1mm)\n M = -99999999999999.0\n DO WHILE ((NORTHING-N0-M).GE.1)\n\tM = B*F0*( (1 +N +5/4.*N**2 +5/4.*N**3)*(PX-P0_RAD)- \n 1 (3*N +3*N**2 +21/8.*N**3) *SIN(PX-P0_RAD) *COS(PX+P0_RAD) + \n 2 (15/8.*N**2 +15/8.*N**3)*SIN(2*(PX-P0_RAD))*COS(2*(PX+P0_RAD))\n 3 -(35/24.*N**3) *SIN(3*(PX-P0_RAD)) *COS(3*(PX+P0_RAD)) )\nc \n\tPXNEW = (NORTHING-N0-M)/(A*F0) + PX \n\tPX = PXNEW \n ENDDO\nc \n V = A*F0*(1-ESQ*SIN(PX)**2)**(-0.5) \n R = A*F0*(1-ESQ)*(1-ESQ*SIN(PX)**2)**(-1.5) \n ETASQ = V/R -1.0\nc \n I7 = DTAN(PX)/(2*R*V) \n I8 = DTAN(PX)/(24*R*V**3)*(5+3*TAN(PX)**2+ETASQ -9*(TAN(PX)**2)*\n 1 ETASQ**2) \n I9 = TAN(PX)/(720*R*V**5) *(61 +90*TAN(PX)**2 +45*(TAN(PX)**4))\n I10 = 1/COS(PX)/V \n I11 = 1/COS(PX)/(6*V**3) * (V/R +2*TAN(PX)**2) \n I12 = 1/COS(PX)/(120*V**5) *(5 +28*TAN(PX)**2 +24*TAN(PX)**4) \n I12A = 1/COS(PX)/(5040*V**7) *(61 +622*TAN(PX)**2 + \n 1 1320*TAN(PX)**4 +720*TAN(PX)**6) \n LATITUDE = PX-I7*(EASTING-E0)**2 +I8*(EASTING-E0)**4 \n 1 -I9*(EASTING-E0)**6 \n LONGITUDE = L0_RAD +I10*(EASTING-E0) - I11*(EASTING-E0)**3 + \n 1 I12*(EASTING-E0)**5 - I12A*(EASTING-E0)**7 \nc\nc//! Equation: 52\nc//! Description: Routine to take Easting and Northings to convert\\\nc//! to 'conventional' Latitude and longitude (in radians). The \\\nc//! contsnts used are specifically set for the UK OS36 system\\\nc//! This routine is believed to be correct and is based on the OS\\\nc//! manual - it should be noted that accuarcy is Unknown- the best\\\nc//! guess is to about 20m. \\\\\nc//! INPUTS: Easting; Northing ; Latitude; Longitude; Pi\\\nc//! Bibliography: A Guide to coordinate systems in Great Britain,\\\nc//! An introduction to mapping systems and the use of GPS datasets\\\nc//! with Ordnance Survey mapping (1999), Ordnance Survey, Southampton.\nc\nc//! E: See the reference - far to complicated!!\nc\nc//! Variable: Latitude\nc//! Description: Returned Latitude value \nc//! Units: Radians (North)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: Longitude\nc//! Description: Returned Longitude value \nc//! Units: Radians (East; for West, negative number returned)\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: Easting\nc//! Description: Easting coordinate of the OS National Grid\nc//! Units: m \nc//! Type: REAL*8\nc\nc//! Variable: Northing\nc//! Description: Northing coordinate of the OS National Grid\nc//! Units: m \nc//! Type: REAL*8\nc\n RETURN \n END \n\n\n REAL*8 FUNCTION DAYDATA_FROM_MONTHDATA_FN(MONTHDATA,\n 1 DAY_OF_MONTH)\n IMPLICIT NONE\n\nc** obtains a single element from and array containing a months worth\nc** of data.\n REAL*8 MONTHDATA(31)\n INTEGER*4 DAY_OF_MONTH\nc\n DAYDATA_FROM_MONTHDATA_FN = MONTHDATA(DAY_OF_MONTH)\nc\nc//! Equation: 53\nc//! Description: Simple 'get' routine, to extract a single bit of\\\nc//! data from an array with a months worth of data. \\\\\nc//! INPUTS: Array with the month's data; Day of the month\nc//! Bibliography: none\nc\nc//! E: DayData = MonthData(dd)\nc\nc//! Variable: DayData\nc//! Description: returned element of the array\nc//! Units: Same as contents of MonthData\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: MonthData\nc//! Description: Array of size 31 with data for a month in it\nc//! Units: whatever the data is\nc//! Type: REAL*8\nc\nc//! Variable: dd\nc//! Description: Day of the month - index for referencing the element\\\nc//! in the array\nc//! Units: None (Day number of month)\nc//! Type: REAL*8\nc\nc RETURN\n END\n\n\n REAL*8 FUNCTION HUMIDITY_FN(TEMP_AIR_AMPLITUDE)\n IMPLICIT NONE\n\nc** humidity based on the temperature max-min amplitude\n REAL*8 TEMP_AIR_AMPLITUDE, RHFUN\nc\n RHFUN = (110.3-(4.68*TEMP_AIR_AMPLITUDE))\nc RHFUN = 77.4-3.289*TEMP_AIR_AMPLITUDE+27.357\n IF(RHFUN.LE.5) THEN\n\tHUMIDITY_FN = 5.0\n ELSE IF(RHFUN.GE.100) THEN\n\tHUMIDITY_FN = 100.0\n ELSE\n\tHUMIDITY_FN = RHFUN\n ENDIF\nc\nc//! Equation 54\nc//! Description: Returns an estimate of the daily humidity based \\\nc//! on the difference between Tmax and Tmin (the amplitude) \\\\\nc//! INPUTS: amplitude os the temperature difference (Tmax - Tmin)\nc//! Bibliography: S Evans (SWELTER)\nc\nc//! Case: RH_x <= 5\nc//! E: RH = 5.0\nc//! Case: RH_x >=100\nc//! E: RH = 100\nc//! Case: 5 < RH_x <100\nc//! E: RH = RH_x \\\\\nc//! \\\\\nc//! E: RH_x = (110.3-(4.68*\\Delta T_{air}))\nc\nc//! Variable: RH\nc//! Description: Relative humidity\nc//! Units: %\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: \\Delta T_{air}\nc//! Description: Amplitude of temperature variation during the day\nc//! Units: \\deg C\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n SUBROUTINE GET_GRIDSQ_SUB(GRIDSIZE, LATITUDE, LONGITUDE, \n 1 GRIDLAT, GRIDLONG, PI, LONG_OFFSET)\n IMPLICIT NONE\n\nc** This routine gets a grid square reference point from latitude and \nc** longitude it assumes that the grid reference point is at the center\nc** of the grid square, and therefore any location within the square\nc** refers back to the central point. Incomming Latitude and LOngitude\nc** is assumed to be in radians, and westerly longitude denoted by\nc** use of a negative number. The parameter LONG_OFFSET is used to \nc** to a 360 degree basis if necessary. Ie. 1 deg West is expected as \nc** -1 deg (in radians). If LONG_OFFSET is zero, then the negative \nc** aspect is maintained, if it is 360, then 1 deg W becomes 359 deg (E)\nc** At the moment this deals only with the Northern Hemisphere\n REAL*8 GRIDSIZE, LATITUDE, LONGITUDE, GRIDLAT, GRIDLONG\n REAL*8 PI, LONG_OFFSET, SIGN, LATDEG, LONGDEG\nc\nc convert lat * long to degrees (easier reference)\n LATDEG = LATITUDE*180.0/PI\n LONGDEG = LONGITUDE*180.0/PI\nc\n GRIDLAT = INT(LATDEG/GRIDSIZE)*GRIDSIZE+GRIDSIZE/2.0\n SIGN = 1\n IF(LONGDEG.lt.0) SIGN = -1\n GRIDLONG = INT(LONGDEG/GRIDSIZE)*GRIDSIZE+GRIDSIZE/2.0*SIGN+\n 1 LONG_OFFSET\nc print*, latdeg, gridlat, longdeg, gridlong\nc\nc//! Equation: 55\nc//! Description: from a given lat-long reference for the Northern \\\nc//! hemisphere, (negative numbers for Westerly longitude), this \\\nc//! pinpoints a reference grid point, assuming uniform grid squares\\\nc//! centered at the grid reference point. The value returned is in \\\nc//! degrees. a value offset can be used to deal with E/W longitude\\\nc//! in slightly different ways. (see description of offset variable)\\\\\nc//! INPUTS: Grid-square size; latitude of site (radians); \\\nc//! longitude of site (radians);\\\nc//! Grid-reference latitude [output]; Grid-reference longitude \\\nc//! [output]; Constant, Pi, longitude offset\nc//! Bibliography: T Randle (2000) - seemed like a good idea at the time\nc\nc//! E: GR_{lat} = INT(LAT/GR_{size}) GR_{size} + GR_{size)/2.0 \\\\\nc//! \\\\\nc//! E: GR_{long} = INT(LONG/GR_{size}) Gr_{size} + \\\nc//! GR_{size) S/2.0 + LAT_{off} \\\nc//! S = 1 if LONG >=0; Else S=-1 if LONG <0\nc\nc//! Variable: GR_{lat}\nc//! Description: Grid-point center latitude value \nc//! Units: Degrees \nc//! Type: REAL*8\nc//! SET\nC\nc//! Variable: GR_{long}\nc//! Description: Grid-point center longitude value \nc//! Units: Degrees \nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: LAT\nc//! Description: Latitude of the site (Northern Hemishpere only) - in \\\nc//! the above equations LAT has been transformed into degrees, though\\\nc//! the input to the routine is radians\nc//! Units: Degrees (in calculation); (radian in input)\nc//! Type: REAL*8\nc\nc//! Variable: LONG\nc//! Description: Longitude of the site (Northern Hemishpere only) - in\\\nc//! the above equations LONG is transformed into degrees, though\\\nc//! the input to the routine is radians\nc//! Units: Degrees (in calculation); (radian in input)\nc//! Type: REAL*8\nc\nc//! Variable: GR_{size}\nc//! Description: Size of the grid-square\nc//! Units: degrees\nc//! Type: REAL*8\nc\nc//! Variable: LAT_{off}\nc//! Description: Offset value to deal with different formats of \\\nc//! longitude. If Westerly values are needed as negative, then \\\nc//! LAT_{off} should be 0; if degrees from east are required, then\\\nc//! it should have the value 360\nc//! Units: degrees\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION VP_UNSAT2_FN(VP_SAT, HUMIDITY)\n IMPLICIT NONE\n\nc** reverses the humidity function and derives the vapour pressure \nc** (unsaturated) from the saturated VP (at the current temp) and \nc** humidity\n REAL*8 VP_SAT, HUMIDITY\nc\n VP_UNSAT2_FN = HUMIDITY*VP_SAT/100.0\nc\nc//! Equation: 56\nc//! Description: Reverses the humidity function and derives the \\\nc//! vapour pressure unsaturated) from the saturated VP (at the \\\nc//! current temp) and humidity \\\\\nc//! INPUTS: Saturated vapour pressure; humidity\nc//! Bibliogrpahy: none\nc\nc//! E: VP_{unsat} = {RH VP_{sat}}\\over {100.0}\nc\nc//! Variable: VP_{unsat} \nc//! Description: unsaturated vapour pressure\nc//! Units: mbar (or same units as VP_{sat}\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: VP_{sat} \nc//! Description: saturated vapour pressure\nc//! Units: mbar (or other eg kPa - will change VP_{unsat} units)\nc//! Type: REAL*8\nc\nc//! Variable: RH\nc//! Description: Relative humidity\nc//! Units: %\nc//! Type: REAL*8\nc\n RETURN\n END \n\n\n REAL*8 FUNCTION RAD_TO_RADPAR_FN(RAD, RAD_PERC_PAR)\n IMPLICIT NONE\n\nc** function to convert 'global' radiation to the radiation falling\nc** within the photosynthetically active wavelengths; circa 375-800nm\nc** the value for this may vary somewhere between 35% and 60% - a \nc** general approximation seems to be around 45%\n REAL*8 RAD, RAD_PERC_PAR\nc\n RAD_TO_RADPAR_FN = RAD*RAD_PERC_PAR/100.0\nc\nc//! Equation: 57\nc//! Description: Converts 'global' radiation to the radiation \\\nc//! falling in the photosynthetically active wavelengths; circa \\\nc//! 375-800nm \\\\\nc//! INPUTS: Total light; percentage of total light that is \\\nc//! photosynthetically active\nc//! Bibliography: S Evans (SWELTER); Salisbury & Ross (1992), \\\nc//! Plant Physiology, Wadsworth Publishing, California (pp613)\nc\nc//! E: RAD_{PAR} = RAD RAD_{perc, PAR}/100.0\nc\nc//! Variable: RAD_{PAR} \nc//! Description: Photosynthetically active radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD\nc//! Description: Total radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc\nc//! Variable: RAD_{perc,PAR}\nc//! Description: Percentage of total radiation that is in the PAR range\nc//! Units: none (percentage)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RADPAR_TO_RAD_FN(RADPAR, RAD_PERC_PAR)\n IMPLICIT NONE\n\nc** function to convert radiation falling\nc** within the photosynthetically active wavelengths; circa 375-800nm\nc** to total radiation \nc** the value for this may vary somewhere between 35% and 60% - a \nc** general approximation seems to be around 45%\n REAL*8 RADPAR, RAD_PERC_PAR\nc\n RADPAR_TO_RAD_FN = RADPAR/RAD_PERC_PAR*100.0\nc\nc//! Equation: 58\nc//! Description: Converts PAR radiation to the total radiation \\\\\nc//! INPUTS: photosynthetically active; percentage of total light \\\nc//! that is photosynthetically active\nc//! Bibliography: S Evans (SWELTER); Salisbury & Ross (1992), \\\nc//! Plant Physiology, Wadsworth Publishing, California (pp613)\nc\nc//! E: RAD = RAD_{PAR} 100.0 / RAD_{perc, PAR}\nc\nc//! Variable: RAD\nc//! Description: Total radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{PAR}\nc//! Description: Photosynthetically active radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc\nc//! Variable: RAD_{perc,PAR}\nc//! Description: Percentage of total radiation that is in the PAR range\nc//! Units: none (percentage)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RADPAR_TO_RADPPFD_FN(RADPAR, \n 1 PPFDCONV)\n IMPLICIT NONE\n\nc** function to convert PAR radiation to photosynthtic flux density\nc** general approximation seems to be around: 1W (PAR) = 4.5 umol PAR\n REAL*8 RADPAR, PPFDCONV\nc\n RADPAR_TO_RADPPFD_FN = RADPAR*PPFDCONV\nc\nc//! Equation: 59\nc//! Description: Converts PAR radiation to the PPFD PAR \\\\\nc//! INPUTS: PAR radiation; conversion of PAR light to PPFD \nc//! Bibliography: S Evans (SWELTER); Salisbury & Ross (1992), \\\nc//! Plant Physiology, Wadsworth Publishing, California (pp613)\nc\nc//! E: RAD_{PPFD} = RAD_{PAR} PPFD_{conv}\nc\nc//! Variable: RAD_{PPFD} \nc//! Description: Photosynthetic flux density (umol/m2)\nc//! Units: umol (PAR) /m^2\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{PAR}\nc//! Description: Photosynthetically active radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc\nc//! Variable: PPFD_{conv}\nc//! Description: Conversion factor for convertinq W (PAR) to umol (PAR)\nc//! Units: umol(PAR)/m^2 / W(PAR)/m^2\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RADPPFD_TO_RADPAR_FN(RADPPFD, \n 1 PPFDCONV)\n IMPLICIT NONE\n\nc** function to convert photosynthtic flux density to PAR radiation \nc** general approximation usess around: 1W (PAR) = 4.5 umol PAR\n REAL*8 RADPPFD, PPFDCONV\nc\n RADPPFD_TO_RADPAR_FN = RADPPFD/PPFDCONV\nc\nc//! Equation: 60\nc//! Description: Converts PPFD PAR to PAR radiation\\\\\nc//! INPUTS: PPFD PAR ; conversion of PAR light to PPFD \nc//! Bibliography: S Evans (SWELTER); Salisbury & Ross (1992), \\\nc//! Plant Physiology, Wadsworth Publishing, California (pp613)\nc\nc//! E: RAD_{PAR} = RAD_{PPFD} PPFD_{conv}\nc\nc//! Variable: RAD_{PAR}\nc//! Description: Photosynthetically active radiation (W/m2)\nc//! Units: W/m^2\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{PPFD} \nc//! Description: Photosynthetically active flux density\nc//! Units: umol (PAR) /m^2\nc//! Type: REAL*8\nc\nc//! Variable: PPFD_{conv}\nc//! Description: Conversion factor for convertinq W (PAR) to umol (PAR)\nc//! Units: umol(PAR)/m^2 / W(PAR)/m^2\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION RAD_DIFF_ABOVE_FN(DIFFPROP_DAY, \n 1 RAD_TERRA_DAY, ALBEDO_DIFF)\n IMPLICIT NONE\n\nc** works out the amount of terrestrial radiation that hits a canopy\nc** that is diffuse - this is after albedo reflection has occurred.\n REAL*8 RAD_TERRA_DAY, ALBEDO_DIFF\n REAL*8 DIFFPROP_DAY\nc\n RAD_DIFF_ABOVE_FN = RAD_TERRA_DAY*DIFFPROP_DAY*(1-ALBEDO_DIFF)\nc\nc//! Equation: 61\nc//! Description: The amount of terrestrial radiation above the \\\nc//! canopy that is diffuse - after albedo reflection \\\\\nc//! INPUTS: proportion of terrestrial radiation that is diffuse;\\\nc//! terrestrial radiation; Albedo (reflection) for diffuse light\nc//! Bibliography: none\nc\nc//! E: RAD_{abv,D} = RAD_{terra} Diff_{prop} (1-ALB_{D})\nc\nc//! Variable: RAD_{abv,D}\nc//! Description: Diffuse radiation above the canopy after albedo\\\nc//! reflection\nc//! Units: W/m^2/day\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{terra}\nc//! Description: Terrestrial radiation \nc//! Units: W/m^2/day\nc//! Type: REAL*8\nc\nc//! Variable: Diff_{prop}\nc//! Description: proportion of Terrestrial radiation that is diffuse \nc//! Units: none (proportion)\nc//! Type: REAL*8\nc\nc//! Variable: ALB_{D}\nc//! Description: Albedo (reflection) coefficient for diffuse light \nc//! Units: none (proportion)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n REAL*8 FUNCTION RAD_BEAM_ABOVE_FN(DIFFPROP_DAY, \n 1 RAD_TERRA_DAY, ALBEDO_BEAM)\n IMPLICIT NONE\n\nc** works out the amount of terrestrial radiation that hits a canopy\nc** that is direct (beam)- this is after albedo reflection has occurred.\n REAL*8 RAD_TERRA_DAY, ALBEDO_BEAM\n REAL*8 DIFFPROP_DAY\nc\n RAD_BEAM_ABOVE_FN = RAD_TERRA_DAY*(1-DIFFPROP_DAY)*(1-ALBEDO_BEAM)\nc\nc//! Equation: 62\nc//! Description: The amount of terrestrial radiation above the \\\nc//! canopy that is direct (beam) - after albedo reflection \\\\\nc//! INPUTS: proportion of terrestrial radiation that is diffuse;\\\nc//! terrestrial radiation; Albedo (reflection) for beam light\nc//! Bibliography: none\nc\nc//! E: RAD_{abv,B} = RAD_{terra} (1-Diff_{prop}) (1-ALB_{B})\nc\nc//! Variable: RAD_{abv,B}\nc//! Description: Direct (beam) radiation above the canopy after albedo\\\nc//! reflection\nc//! Units: W/m^2/day\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: RAD_{terra}\nc//! Description: Terrestrial radiation \nc//! Units: W/m^2/day\nc//! Type: REAL*8\nc\nc//! Variable: Diff_{prop}\nc//! Description: proportion of Terrestrial radiation that is diffuse \nc//! Units: none (proportion)\nc//! Type: REAL*8\nc\nc//! Variable: ALB_{B}\nc//! Description: Albedo (reflection) coefficient for direct (beam)light \nc//! Units: none (proportion)\nc//! Type: REAL*8\nc\n RETURN\n END\n\n \n\n\nc----------------------------------------------------------\n\n SUBROUTINE RAIN_DURATION2_SUB(RAIN, RAIN_DURATION, RAIN_INTENSITY,\n 1 DAYS_IN_MONTH, IS1, IS2, IS3)\n\t IMPLICIT NONE\n\n\n\nc** This routine estimates the duration and intensity of rain on each day \nc** for a month Accuracy is suspect.\n REAL*8 RAIN(31), RAIN_DURATION(31), RAIN_INTENSITY(31)\n REAL*8 RAIN_LIM(10), TIMESCALE, FREQUENCY, PROB, RNDF\n REAL*8 XLO, XHI\n INTEGER*4 DAYS_IN_MONTH, IDAY, CLASSNO, MAX_RAINTIME, I \n INTEGER*4 IS1, IS2, IS3\nc \n RAIN_LIM(1) = 0 \n RAIN_LIM(2) = 5 \n RAIN_LIM(3) = 10 \n RAIN_LIM(4) = 15 \n RAIN_LIM(5) = 20 \n RAIN_LIM(6) = 25 \n RAIN_LIM(7) = 50 \n RAIN_LIM(8) = 75 \n RAIN_LIM(9) = 100 \n\nc** find which rain class the current preciptation is in\n DO 10 IDAY = 1, DAYS_IN_MONTH\n\tIF(RAIN(IDAY).GT.0) THEN\n\t IF(RAIN(IDAY).GT.RAIN_LIM(9)) THEN\n\t CLASSNO = 9\n\t ELSE\n\t DO 20 I = 9,2,-1\n\t IF(RAIN(IDAY).LE.RAIN_LIM(I)) CLASSNO = I\n20 CONTINUE\n\t ENDIF\nc** The maximum duration of a rain instance is\n\t MAX_RAINTIME=MIN(24,INT(.5*EXP(0.1386*RAIN_LIM(CLASSNO))+.5))\nc\nc** The cumulative number of rainy days of a class type per century \nc** is proportional to the rainfall duration. \nc** (ie: Rainy days of this magnitude per century is timescale*duration)\nc\n\t TIMESCALE = 1.39*((RAIN_LIM(CLASSNO)/25.4+0.1)**(-3.55))*10\nc\nc** thus the cumulative instances of rain of this magnitude (per century)is\n\n\t FREQUENCY = TIMESCALE*MAX_RAINTIME\nc\nc** the probability of rain falling at some stage within time, t, is\nc prob = timescale*t/frequency; thus if we get a random number between \nc** 0.025 and 1 (ignoring the chances of P<0.025; then the rain \nc** duration (minutes) is\nc\n\t XLO = 0.025\n\t XHI = 1.0\n\t PROB = RNDF(XLO, XHI, IS1, IS2, IS3)\n\t RAIN_DURATION(IDAY) = PROB/TIMESCALE*FREQUENCY*60\nc\nc** the intensity (mm/hour) is\n\t RAIN_INTENSITY(IDAY) = 60.0/RAIN_DURATION(IDAY)*RAIN(IDAY)\n\tELSE \n\t RAIN_DURATION(IDAY)=0.0\n\t RAIN_INTENSITY(IDAY)=0.0\n\tENDIF\n10 CONTINUE\n RETURN\n END\n\n\n\n REAL*8 FUNCTION VP_SAT2_FN(TEMP_C)\n IMPLICIT NONE\n\nc** Returns the saturated air pressure for a given temperature\n REAL*8 TEMP_C\nc\n IF(TEMP_C.GE.0 ) THEN\n\tVP_SAT2_FN = 610.78*exp(17.269*TEMP_C/(TEMP_C+237.3))\n ELSE\n\t VP_SAT2_FN = exp(-6140.4/(273+TEMP_C)+28.916)\n\t Endif\nc\nc//! Equation: 71\nc//! Description: Returns saturated vapour pressure for a temperature\\\\\nc//! INPUTS: Temperature\nc//! Bibliography: http://www.natmus.dk/cons/tp/atmcalc/atmoclc1.htm (26.01.2001)\nc\nc//! Case: if T>=0\nc//! E: VP_{sat} = 610.78*exp(T\\over{(T+238.3)}*17.2694) \nc//! Case: t<0 \nc//! E: VP_{sat} = exp(-6140.4\\over{(273+T)}+28.916) \nc\nc//! Variable: VP_{sat}\nc//! Description: saturated vapour pressure at a given temperature\\\\\nc//! typical ranges are 300-1200 Pa: 0.3-1.2kpa: 3-12mbar\nc//! Units: Pa\nc//! SET\nc//! Type: REAL*8\nc\nc//! Variable: T\nc//! Description: Air temperature \nc//! Units: Degrees C \nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION TRANS_PROP_DAY2_FN(TEMP_AIR_AMPLITUDE,\n 1 A_SKY, ANGSTROM_BETA, C_SKY) \n IMPLICIT NONE\n\nc** determines aproximate transmittance of radiatio to the earth\n REAL*8 TEMP_AIR_AMPLITUDE\n REAL*8 A_SKY, ANGSTROM_BETA, C_SKY\n\n IF (TEMP_AIR_AMPLITUDE.LE.0) THEN\n\t TRANS_PROP_DAY2_FN = ANGSTROM_BETA\n ELSE\n\t TRANS_PROP_DAY2_FN = ANGSTROM_BETA*(1-\n 1 EXP(-A_SKY*TEMP_AIR_AMPLITUDE**C_SKY))\n ENDIF\n \nc\nc//! Equation: 72\nc//! Description: Works out the transmittance of radiation through the\\\nc//! atmosphere - a reverse engineered approximation of eqn 41. Untested\nc//! and certainly dubious at low temperature amplitudes as we fix it to\\\nc//! be Angstrom_beta; ehreas the original allows for transmittance to be\\\nc//! > Angstrom_beta\\\\\nc//! INPUTS: Air temperature amplitude (max-min); \\\nc//! Coefficient for maximum clear-sky transmittance; \\\nc//! Angstrom \\beta value; Coefficient of clear-sky transmittance \\\nc//! with amplitude temperature increase. \nc//! Bibliography: S Evans (SWELTER); Bristow & Campbell (1984) Agric \\\nc//! & Forest Met 31: 159-166\nc\nc//! Case: \\Delta_T <=0.0\nc//! E: T_{sw} = \\beta\nc//! Case: \\Detla_T > 0\nc//! E: T_{sw} = \\beta(1-exp(-A_{sky}*\\Delta_T^{C_{sky}})) \nc\nc//! Variable: T_{sw}\nc//! Description: proportion of Extra-terrestrial radiation that \\\nc//! arrives on the earth's surface as short-wave.\nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: \\Delta T\nc//! Description: Daily amplitude of temperature variation\nc//! Units: Degrees C (usually)\nc//! Type: REAL*8\nc\nc//! Variable: \\beta\nc//! Description: Angstrom tubidity factor: max clear sky transmittance\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: A_{sky}\nc//! Description: Coefficient of maximum clear-sky transmittance \\\nc//! characteristics\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: C_{sky}\nc//! Description: Coefficient of maximum clear-sky transmittance \\\nc//! with \\Delta T increase\nc//! Units: none \nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION GAMMADIST_FN(A,B,C, SEED1, SEED2, SEED3)\n IMPLICIT NONE\n\n\n REAL*8 Aconst, Bconst, Cconst, Qconst, Tconst\n REAL*8 Dconst, a, b, c, xlo, xhi, R1, R2, P, Y\n REAL*8 retval, p1, p2, v, z, w, rndf, R3\n integer*2 flag\n integer*4 seed1, seed2, seed3\n Bconst = c-log(4.0)\n Tconst = 4.5\n Dconst = 1+log(Tconst)\n Cconst = 1+c/exp(1.0)\n flag = 1\n Xlo = 0.0\n xhi = 1.0\nc print*, 'in gammadist', a,b,c, seed1, seed2, seed3\n\n if(c.lt.1) then\n\t flag =0\n100 R1 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\t p = Cconst*R1\n\t if(P.GT.1) GOTO 300\n y=p**(1/c)\n\t R2 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\t if(R2.le.exp(-y)) then\n\t retval = a+b*y\n\t flag = 2\n\t endif\n\t if(flag.eq.0) goto 100\n\n300 y = -log((Cconst-p)/c)\n\t r2 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\t if((y.GT.0).AND.(R2.le.y**(c-1))) then\n\t retval = a+b*y\n\t flag = 3\n endif \n if(flag.eq.0) goto 100\nc print *,flag,'=',retval\n\n elseif(c.gt.1) then\n Aconst = 1/SQRT(2*c-1.0) \n Qconst = c+ 1/(Aconst)\n\t flag=0 \n20 p1 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\t p2 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\t v = Aconst*log(p1/(1-p1))\n\t y = c*exp(v)\n\t z = p1*p1*p2\n\t w = Bconst+Qconst*v - y\n\t if(w+Dconst-Tconst*z.ge.0) then\n\t retval =a+b*y\n\t flag = 3\n\t else\n\t if(w.ge.log(z)) then\n\t retval = a+b*y\n\t flag = 4\n\t endif\n\t endif\n\t if(flag.eq.0) goto 20\n else\n r3 = RNDF(XLO,XHI, SEED1, SEED2, SEED3)\n if(b.gt.0) then\n retval = a-b*log(r3)\n else\n print*, 'problem with gamma dist when c=1'\n stop\n endif\n endif\n\n gammadist_fn = retval \nc//! Equation: 73\nc//! Description: Derives a random value from the gamma distribution \\\\\nc//! INPUTS: 3 parameters describing the gamma distribution shape; 3\\\nc//! Seeds for random number generation\nc//! Bibliography: R Saucier (2000), Computer generation of statistical\\ \nc//! Distributions; (US) Army Research Laboratory, ARL-TR-2168.\\\nc//! (http://ftp.arl.mil/random/ (17/5/2001) )\nc\n return\n end\n\n \n REAL*8 FUNCTION NORM_FROM_RAND_FN(MEAN, SD, SEED1,SEED2,\n + SEED3, NORMSWITCH)\n\n IMPLICIT NONE\n\n REAL*8 Mean, SD, NormVal\n REAL*8 NORMDIST_FN, NORMDIST2_FN, TRANSNORM_FN\n Integer*4 Seed1, Seed2, Seed3, NormSwitch\nc//! Equation: 86\nc//! Description: Generates a value from a pseudo normal distribution \\\\\nc//! is a shell for calling different methods. \\\\\nc//! INPUTS: Mean; Sd; 3 Seeds for random number generation; Method id\nc//! Bibliography: None\nc\n IF(NormSwitch.EQ.1) then\n NormVal = NORMDIST_FN(SEED1,\n + SEED2,SEED3)\n* IF((MEAN.NE.Zero).and.(SD.NE.1)) THEN\n IF ((abs(MEAN).GT.0.0d0).AND.(abs(SD-1.0d0).GT.0.0d0)) THEN\nc transform the distribution\n NormVal = TRANSNORM_FN(Mean, SD, NormVal)\n ENDIF\n Else if(NormSwitch.eq.2) THEN\n NormVal = NORMDIST2_FN(MEAN,SD,SEED1,SEED2,SEED3)\n EndIF\n NORM_FROM_RAND_FN = NormVal\n\n Return\n END\n\n\n REAL*8 FUNCTION NORMDIST_FN(SEED1,\n + SEED2,SEED3)\n IMPLICIT NONE\n\n REAL*8 xlo, xhi, R1, retval, rndf\n integer*4 seed1, seed2, seed3\n \n Xlo = 0.0\n xhi = 1.0\n R1 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\n Retval = ( R1**0.135 - (1-R1)**0.135 )/0.1975\n\n NORMDIST_FN = Retval\nc//! Equation: 74\nc//! Description: Derives a value from standard normal distribution\\\nc//! (mean 0, sd 1), at random. Reputed to have accuracy of 0.5% in\\\nc//! The range 0<=p<=0.9975 (NB random numbers are between 0 and 1) \\\\\nc//! INPUTS: 3 Seeds for random number generation\nc//! Bibliography: S Evans, SWELTER; Haith, DA, Tubbs, LJ and \\\nc//! Pickering, NB(1984) Simulation of Pollution by soil erosion and \\\nc//! soil nutrient loss; Pudoc, Wageningen.\nC\nC//! E: N = { R1^{0.135} - (1-R1)^{0.135)} } \\over {0.1975}\nC \nc//! Variable: SEED1, SEED2, SEED3\nc//! Description: Integer seeds for random number generation\nc//! Units: none \nc//! Type: Integer\nc\nc//! Variable: R1\nc//! Description: Random number between 0 and 1\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: NORMDIST_FN\nc//! Description: Simulated value from a normal distribution N(0,1)\nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\n\n return\n end\n\n\n\n REAL*8 FUNCTION NORMDIST2_FN(MEAN,SD,SEED1,SEED2,SEED3)\n IMPLICIT NONE\n\n\n REAL*8 MEAN, SD\n REAL*8 xlo, xhi, R1, R2, P, retval, rndf \n integer*4 seed1, seed2, seed3\nc\n Xlo = -1.0\n xhi = 1.0\n P = 2.0\nc \n10 IF (P.GE.1.0d0) THEN \n\tR1 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\tR2 = RNDF(XLO, XHI, SEED1, SEED2, SEED3)\n\tP = R1*R1 + R2*R2\n GOTO 10\n ENDIF\n\nc\n Retval = MEAN + SD*R1*SQRT(-2.0*LOG(P)/P)\nC NB . . Natural Log!\nc\n NORMDIST2_FN = Retval\nc\nC//! Equation: 75\nc//! Description: Derives a random value from the Normal distribution\\\\\nc//! INPUTS: 2 parameters describing the distribution shape;- Mean \\\nc//! And Standard deviation; 3 Seeds for random number generation\nc//! Bibliography: R Saucier (2000), Computer generation of statistical\\\nc//! Distributions; (US) Army Research Laboratory, ARL-TR-2168; \\\nc//! (http://ftp.arl.mil/random/ (17/5/2001) )\nc\nc//! E: N(\\mu, \\sigma) = \\mu + \\sigma R1 \\root{(-2 Ln(P)/P)} \\\nc//! Where P = R1^2 + R2^2\nC \nc//! Variable: SEED1, SEED2, SEED3\nc//! Description: Integer seeds for random number generation\nc//! Units: none \nc//! Type: Integer\nc\nc//! Variable: R1, R2\nc//! Description: Random number between -1 and +1\nc//! Units: none \nc//! Type: REAL*8\nc\nc//! Variable: NORMDIST2_FN\nc//! Description: Simulated value from a normal distribution \\\nc//! N(\\mu,\\sigma)\nc//! Units: none\nc//! Type: REAL*8\nc//! SET\nc\nc print*, 'done normdist2'\n return\n end\n\n\t\n* REAL*8 FUNCTION LAT_SLOPE_FN(Incl_rad, Lat_rad, \n* 1 Aspect_rad, Pi)\n* IMPLICIT NONE\n\n* REAL*8 Lat_rad, Incl_rad, retval, Pi, Aspect_rad\nc\n* retval = COS(Incl_rad)*SIN(Lat_rad)+\n* 1 SIN(Incl_rad)*COS(Lat_rad)*COS(Aspect_rad) \n* if(retval.lt.-1) retval = -1.0\n* if(retval.gt.1) retval = 1.0 \n* retval=ASIN(retval)\nc\nc//! Equation 76\nc//! Description: calculates an equivalent latitude for a point, \\\nc//! given a slope and inclination\\\\\nc//! INPUTS: Inclination (from horizontal); Latitude; Aspect; Pi\nc//! Bibliography: Swift, L.W. (1976) Algorithm for Solar Radiation on \\\nc//! Mountain Slopes Water Resources Research (12) 1: 108-112\nc\nc//! E: Lat_{slope} = ASIN(COS(Incl_{rad}*SIN(Lat_{rad}+ \\\nc//! COS(Lat_{rad})*SIN(Asp_{rad}))\nc\nc//! Variable: Incl_{rad}\nc//! description: Inclination of the slope (from horizontal)\nc//! Units: Raidans \nc//! Type: REAL*8\nc\nc//! Variable: Lat_{rad}\nc//! description: latitude of the site\nc//! Units: Raidans \nc//! Type: REAL*8\nc\nc//! Variable: Asp_{rad}\nc//! description: Aspect (Azimuth) of the slope (from North)\nc//! Units: Raidans \nc//! Type: REAL*8\nc\nc//! Variable: Pi\nc//! Description: mathematical constant, pi\nc//! Units: none\nc//! Type: REAL*8\nc\nc//! Variable: Lat_{slope}\nc//! Description: Latitude of an equivalent point, accounting for \\\nc//! the slope & aspect\nc//! Units: radians\nc//! Type: REAL*8\nc//! SET\nc\n* LAT_SLOPE_FN = retval\n* RETURN\n* END\n\n\n REAL*8 FUNCTION RAD_SLOPE_FN(Declin_rad, Lat_rad, \n 1 Lat_slope_rad, Inclin_rad, Aspect_rad, Pi)\n\n IMPLICIT NONE\n\n\n REAL*8 Declin_rad, Lat_rad, Lat_slope_rad, Inclin_rad\n REAL*8 Aspect_rad, Pi\n REAL*8 DAWN_HOURANGLE_FN\n REAL*8 Time_Offset, T, T6, T7, T1, T0, T3, T2, T8, T9\n REAL*8 Rad0, Rad1, Rad_horiz, Adj\n\nc calculate an offset for time for the actual and equivalent slopes\n Time_Offset = ATAN( SIN(Inclin_rad)*SIN(Aspect_rad) /\n 1 ( COS(Inclin_rad)*COS(Lat_rad) -\n 2 SIN(Inclin_rad)*SIN(Lat_rad)*COS(Aspect_rad)) )*Pi/180\nc calculate new 'adjusted' dawn/dusk hour angles\nc print*, 'calling dawn:',Declin_rad, Lat_slope_rad, lat_rad\n T = DAWN_HOURANGLE_FN(Declin_rad, Lat_slope_rad)\n T7 = T-Time_Offset\n T6 = -T-Time_Offset\nc claclulate un-adjusted hour-angles\n T = DAWN_HOURANGLE_FN(Declin_rad, Lat_rad)\n T1 = T\n T0 = -T\n If(T7.LT.T1) THEN\n\tT3 = T1\n Else\n\tT3 = T7\n Endif\n If(T6.GT.T0) THEN\n\tT2 = T6\n Else\n\tT2 = T0\n Endif\nc\nc This bit supposedly guards against double sunrises and 90 degree latitudes \nc UNTESTED!!!\nc Calculate the potential on horizontal surface\n If(T2.GE.T3) THEN\n\tT2 = 0\n\tT3 = 0\n ENDIF\n T6 = T6+Pi\n Rad0 = 0.0\n If(T6.Ge.T1) Then\n\tT8 = T6\n\tT9 = T1\n Else\n\tT7 = T7 - Pi\n\tIf(T7.Gt.T0) Then\n\t T8 = T0\n\t T9 = T7\n\t Rad0 = SIN(Declin_rad)*SIN(Lat_slope_rad)*(T9-T8)*12/Pi + \n 1 COS(declin_rad)*COS(Lat_slope_rad)*\n 2 ( SIN(T9+Time_Offset)-SIN(T8+Time_Offset))*12/Pi\n\tEndif\n Endif\n Rad1 = SIN(Declin_rad)*SIN(Lat_slope_rad)*(T3-T2)*12/Pi + \n 1 COS(declin_rad)*COS(Lat_slope_rad)*\n 2 ( SIN(T3+ Time_Offset)-SIN(T2+ Time_Offset))*12/Pi\n Rad1= Rad1+Rad0\nc Print*, declin_rad, lat_slope_rad, t2, t3\nc\nc Calculate the Potential on a horizontal surface\n Adj = 0.0\n Rad_Horiz = SIN(Declin_rad)*SIN(Lat_rad)*(T1-T0)*12/Pi + \n 1 COS(declin_rad)*COS(Lat_rad)*\n 2 ( SIN(T1+Adj)-SIN(T0+Adj))*12/Pi\nc Print*, declin_rad, lat_rad, t0, t1\n RAD_SLOPE_FN = Rad1/Rad_Horiz\nc Print*, Rad1, Rad_Horiz\n \n\nc//! Equation 77\nc//! Description: Calculates the ratio between horizontal surface \\\nc//! Direct radiation and on a slope it finds an equivalent latitude \\\nc//! for daylength purposes, but uses the correct declinations and \\\nc//! elevations. It appears that the day is still spread evenly about \\\nc//! noon! - this may account for the non-night light that occurs before \\\nc//! the 'new sunrise/set\nc//! Bibliography: Swift, L.W. (1976) Algorithm for Solar Radiation on \\\nc//! Mountain Slopes. Water Resources Research (12) 1: 108-112\nc//! E: Not even going to try - see the paper!!\nc\n RETURN\n END\n\n\n SUBROUTINE RAD_SLOPE_DAY_SUB(RAD_BEAM_SLOPE, RAD_DIFF_SLOPE,\n 1 RAD_TERRA_DAY, DIFFPROP_DAY, SLOPE_RAD, \n 1 ASPECT_RAD, DECLINATION_RAD, LAT_RAD, SUNRISE, PI) \n\t IMPLICIT NONE\n\n REAL*8 RAD_BEAM_SLOPE, RAD_DIFF_SLOPE\n REAL*8 RAD_TERRA_DAY,DIFFPROP_DAY,SLOPE_RAD,ASPECT_RAD\n REAL*8 DECLINATION_RAD, lAT_RAD, SUNRISE, PI\n REAL*8 CT1, SHF, SMP, W, CT2, CT3, CT, CTS, CTZ, ST\n REAL*8 CTZS, TFR, DIFFR\n integer*4 SH,i\nc\nc calculates the adjustment for beam and diffuse light intercepted on\nc a sloping surface. No account is taken of the difference of length\nc of the surface compared to the flat plane!! It also takes no account\nc of increased shading beyond the slope (if facing away from the sun)-\nc we know nothing about surrounding terrain.\n\t \n CT1 = SIN(DECLINATION_RAD)*(SIN(LAT_RAD)*COS(SLOPE_RAD)-\n 1 COS(LAT_RAD)*SIN(SLOPE_RAD)*COS(ASPECT_RAD))\n SH = INT(SUNRISE+1) \n SHF = SH - SUNRISE\n SMP = SUNRISE+SHF/2.0\n W = 15*(SMP-12)*PI/180.0\n CT2 = COS(DECLINATION_RAD)*COS(W)*(COS(LAT_RAD)*COS(SLOPE_RAD)+\n 1 SIN(LAT_RAD)*SIN(SLOPE_RAD)*COS(ASPECT_RAD))\n CT3 = COS(DECLINATION_RAD)*SIN(SLOPE_RAD)*SIN(ASPECT_RAD)*SIN(W)\n CT = CT1+CT2+CT3\n CTS = CT*SHF\n CTZ = COS(LAT_RAD)*COS(DECLINATION_RAD)*COS(W)+\n 1 SIN(LAT_RAD)*SIN(DECLINATION_RAD)\n CTZS = CTZ*SHF\n TFR = CT/CTZ\n \n* DO 10 ST = SH+0.5, 11.5\n DO i=0,11\n ST = SH+i+0.5\n W = 15*(ST-12)*PI/180.0\n CT2 = COS(DECLINATION_RAD)*COS(W)*(COS(LAT_RAD)*COS(SLOPE_RAD)+\n 1 SIN(LAT_RAD)*SIN(SLOPE_RAD)*COS(ASPECT_RAD))\n CT3 = COS(DECLINATION_RAD)*SIN(SLOPE_RAD)*SIN(ASPECT_RAD)*SIN(W)\n CT = CT1+CT2+CT3\n CTS = CTS+CT\n CTZ = COS(LAT_RAD)*COS(DECLINATION_RAD)*COS(W)\n 1 +SIN(LAT_RAD)*SIN(DECLINATION_RAD)\n CTZS = CTZS+CTZ\n tfr = ct/ctz\n \n ENDDO\n*10 CONTINUE\n TFR = CTS/CTZS\nc\nc now diffuse\n DiffR = COS(SLOPE_RAD/2)*COS(SLOPE_RAD/2) \n \n RAD_BEAM_SLOPE = TFR*RAD_TERRA_DAY*(1-DIFFPROP_DAY)\n RAD_DIFF_SLOPE = DiffR*(RAD_TERRA_DAY*DIFFPROP_DAY)\n\nc//! Equation 77\nc//! Description: modifies incomming light to account for a slope and aspect\\\nc//! effect. Sin in the northern hemispere, north facing slopes may \\\nc//! only get diffuse radiation, the light must first be split into \\\nc//! direct (beam) and diffuse light. No account is taken of the change in\\\nc//! surface length, or of any shading beyond the current slope. Hence \\\nc//! total radiation over many surfaces will be greater than over a single,\\\nc//! flat plane. The difference is aprox 1/cos(slope).\nc//! Bibliography:Duffie and Beckman (1991). Solar engineering of thermal\\\nc//! processes. Wiley. Also See groups.google.com; alt.energy.renewable;\\\nc//! Subject: Re: Irradiation; Posted 5/1/1998; accessed 15/6/2001. \\\nc//! Diffuse radiation from Montieth J.L. (1973) Principles of \\\nc//! Environmantal Physics, Arnold, London.\nc//! E: see the references\n\n RETURN\n END\n\n\n REAL*8 FUNCTION TEMP_ALT_CORR_FN(TEMP,\n 1 METALT, ALTITUDE)\n IMPLICIT NONE\n\nc** Function corrects temperature for altitude - should be applied\nc** directly after the temperaure calculation as will therefore\nc** impact on other functions eg SVP etc\n REAL*8 TEMP, METALT, ALTITUDE, ALTDIFF_FT\nc\n ALTDIFF_FT = (ALTITUDE-METALT)*100/2.54/12.0\n TEMP_ALT_CORR_FN = TEMP-(ALTDIFF_FT)/1000.0*2.0 \nc//! Equation: 78\nc//! Description: corrects temperature for site altitude. correction \\\nc//! is approc 2C per 1000 ft \\\\\nc//! INPUTS: Temperature; altitude of met station (m); \\\nc//! Altitude of site (m)\nc//! Bibliography: ??\nc//! \nc//! E: T_{alt} = T-ALT_{diff}*2\nc\nc//! Variable: T_{alt}\nc//! Description: corrected air temperature \\\\\nc//! Units: C\nc//! Type: REAL*8\nc//! SET\nc\nc//! Variable: T\nc//! Description: Temperature at met station elevation\nc//! Units: C\nc//! Type: REAL*8\nc\nc//! Variable: ALT_{diff}\nc//! Description: Altitude difference between site and met station\nc//! Units: Feet\nc//! Type: REAL*8\nc\n RETURN\n END\n\n\n REAL*8 FUNCTION PPT_RAIN_FN(TEMP_DAY_MEAN, RAIN_DAY)\n IMPLICIT NONE\nc\n\n REAL*8 ZERO_SNOW_T, ALL_SNOW_T, TEMP_DAY_MEAN, RAIN_DAY\n REAL*8 RAINPART \n\tZERO_SNOW_T=2.0\n ALL_SNOW_T=-2.0\n\n\tIF(TEMP_DAY_MEAN.GT.ZERO_SNOW_T) THEN\n PPT_RAIN_FN = RAIN_DAY*1.0\n ELSE IF(TEMP_DAY_MEAN.LT.ALL_SNOW_T) THEN\n PPT_RAIN_FN = 0.0\n ELSE\nc some combination of snow and rain\n RAINPART = (TEMP_DAY_MEAN - ALL_SNOW_T)/\n 1 (ZERO_SNOW_T-ALL_SNOW_T)\n PPT_RAIN_FN = RAINPART*RAIN_DAY\n ENDIF\n \nc\nc//! Equation: 79\nc//! Description: Finds the amount of real rain from Gross rain \\\nc//! ie. that which is not snow \\\\ \nc//! INPUTS: Mean Temperature of the day; Daily rainfall.\n \nc//! Bibliography: S Evans; SWELTER. eq.67\nc\nc//! Case: T_{mean} > T_{snow}\nc//! E: PPT_{rain} = PPT_{day}\nc//! Case: T_{mean} < T_{all_snow}\nc//! E: PPT_{rain} = 0.0\nc//! Case: T_{all_snow} < T_{mean} < T_{snow}\nc//! E: PPT_{rain} = (T_{mean} - T_{all_snow})/ \\\nc//! (T_{snow}-T_{all_snow}) * PPT_{day}\nc \nc//! Variable: T_{Mean}\nc//! Description: Mean daily temperature\nc//! Units: Celcius\nc//! Type: REAL*8\nc\nc//! Variable: PPT_{day}\nc//! Description: Gross precipitation\nc//! Units: mm/day\nc//! Type: REAL*8\nc \nc//! Variable: T_{snow} \nc//! Description: Temperature at which snow may start (above which is all rain) \nc//! Units: Celcius\nc//! Type: REAL*8\nc\nc//! Variable: T_{all_snow}\nc//! Description: Temperature below which is all snow \nc//! Units: Celcius\nc//! Type: REAL*8 \nc\nc//! Variable: PPT_{rain}\nc//! Description: Amount of precipitation which is real rain\nc//! Units: mm/day (rain) \nc//! Type: REAL*8\nc//! SET \nc\n RETURN \n END \n\n REAL*8 FUNCTION PPT_SNOW_FN(RAIN_DAY, PPT_RAIN)\n IMPLICIT NONE\nc\n\n REAL*8 RAIN_DAY, PPT_RAIN \n \n\tPPT_SNOW_FN = (RAIN_DAY - PPT_RAIN)*1.1811\n \nc\nc//! Equation: 80\nc//! Description: Finds the amount of snow from Gross rain \\\\\nc//! INPUTS: Daily rainfall; Precipitation which is rain\n \nc//! Bibliography: S Evans; SWELTER. eq.67\nc\nc//! E: PPT_{snow} = (Rain{day} - PPT_{Rain})*1.1811\nc \nc//! Variable: PPT_{day}\nc//! Description: Gross precipitation\nc//! Units: mm/day\nc//! Type: REAL*8\nc\nc//! Variable: PPT_{Rain}\nc//! Desciption: Precipitation which is Rain\nc//! Units: mm/day (rain)\nc \nc//! Variable: PPT_{snow}\nc//! Description: precipitation as snow (snow depth)\nc//! Units: mm/day (snow) \nc//! Type: REAL*8\nc//! SET \nc\n RETURN \n END \n\n\n\n REAL*8 Function TRANSNORM_FN(MU, SD, Xval)\n Implicit none\n\n REAL*8 MU, SD, Xval\nc Transforms a standard normal distribution, N(0,1))\nc to N(Mu, SD)\nc\nC//! Equation: 81\nc//! Description: Transforms a value from a Standard Normal distribution N(0,1) to\\\nc//! a 'generic' normal N(mu, sd)\\\\\nc//! INPUTS: Mean of Distribution; Sd of distribution; Standard Normal value\nc//! Bibliography: None (T Houston Pers Comm)\n TRANSNORM_FN = Xval*SD+Mu\nc\nc//! E: N(\\mu, \\sigma) = N(0,1)*\\sigma + \\mu\nc\nc//! variable: \\mu\nc//! Type: REAL*8\nc//! Description: Mean of the desired normal distribution\nc//! Units: Any\nc\nc//! Variable: \\sigma\nc//! Type: REAL*8\nc//! Description: Standard deviation of the desired normal distribution\nc//! Units: Any\nc\nc//! Variable: N(0,1)\nc//! Type: Double Precsion\nc//! Description: Value from the standard normal distribution\nc//! Units: Any\nc\nc//! Variable: N(\\mu, \\sigma)\nc//! Type: REAL*8\nc//! Description: Transformed Normal Value - from the shifted norma distribution\nc//! Units: Any\nc//! SET\nc\n Return\n End\n\n\n\n\n REAL*8 Function NORMSKEW_FN(NormVal, Lambda)\n Implicit none\n\nc\n REAL*8 NormVal, Lambda\nc Box_cox Normaility transformation of a Normal Distribution\nc\nC//! Equation: 82\nc//! Description: Skews a normal disribution\\\\\nc//! INPUTS: Value from a normal distribution N(Mu,Sd);\\\nc//! And Response variable\nc//! Bibliography: C. Coarkin & P Tobias, NIST/SEMATECH Engineering Handbook;\\\nc//! Ch. 1.3.3.6\\\nc//! http://www.itl.nist.gov/div898/handbook/eda/section3/boxcox.htm (9/8/2001)\nc\nc//! E: SN(N(\\mu,\\sigma)) = (N(\\mu,\\sigma)^\\lambda -1)\\over{\\lambda}\nc \n NORMSKEW_FN = ( (Normval**lambda)-1)/lambda\nc\nc//! Variable: \\\\lambda\nc//! Type: REAL*8\nc//! Description: Response variable - if \\lambda= 0; use log of data\nc//! Units: none\nc\nc//! Variable: N(\\mu,\\sigma)\nc//! Type: REAL*8\nc//! Description: value from the normal distribution\nc//! Units: Any\nc//! Variable: SN(N(\\mu,\\sigma)) \nc//! Type: REAL*8\nc//! Description: box-cox skewed, (transformed) normal value\nc//! Units: Any\nc//! SET\nc\n Return\n End\n\n REAL*8 FUNCTION TAMPFROMRH_FN(RH)\n IMPLICIT NONE\n\nc** humidity based on the temperature max-min amplitude\n REAL*8 RH\n\n TAMPFROMRH_FN = (RH-110.3)/(-4.68)\nc\nc//! Equation 83\nc//! Description: Returns an estimate of the daily air temperature\\\nc//! amplitude based on RH. Inverse of RH equation\\\\\nc//! INPUTS: Relative humidity (%)\nc//! Bibliography: S Evans (SWELTER)\nc\nc//! E: \\Delta T_{air} = (RH-110.3)\\over{(-4.68)}\nc\nc//! Variable: RH\nc//! Description: Relative humidity\nc//! Units: %\nc//! Type: REAL*8\nc\nc//! Variable: \\Delta T_{air}\nc//! Description: Amplitude of temperature variation during the day\nc//! Units: \\deg C\nc//! Type: REAL*8\nc//! SET\nc\n RETURN\n END\n \n", "meta": {"hexsha": "6aa26d92a0170c4736609fef947936a293a2cd37", "size": 128266, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/f90/metdos.f", "max_stars_repo_name": "marklomas60/SDGVM", "max_stars_repo_head_hexsha": "75a941b0305393bff6c807d119ef56e606cdc213", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-24T02:46:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T02:46:00.000Z", "max_issues_repo_path": "source/f90/metdos.f", "max_issues_repo_name": "marklomas60/SDGVM", "max_issues_repo_head_hexsha": "75a941b0305393bff6c807d119ef56e606cdc213", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-08-08T12:59:58.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-08T15:00:58.000Z", "max_forks_repo_path": "source/f90/metdos.f", "max_forks_repo_name": "marklomas60/SDGVM", "max_forks_repo_head_hexsha": "75a941b0305393bff6c807d119ef56e606cdc213", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-08-08T12:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-21T01:35:59.000Z", "avg_line_length": 30.870276775, "max_line_length": 89, "alphanum_fraction": 0.6081268614, "num_tokens": 41050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.8140137129843101}} {"text": "module statistics_module\n\n contains\n subroutine stats(x, n, mean, std_dev)\n implicit none\n\n integer, intent(in) :: n\n real, dimension(:), intent(in) :: x\n real, intent(out) :: mean, std_dev\n real :: variance\n real :: sumxi, sumxi2\n integer :: i\n\n variance = 0.\n sumxi = 0.\n sumxi2 = 0.\n do i = 1, n\n sumxi = sumxi+x(i)\n sumxi2 = sumxi2+x(i)*x(i)\n end do\n mean = sumxi/n\n variance = (sumxi2-sumxi*sumxi/n)/(n-1)\n std_dev = sqrt(variance)\n end subroutine\nend module\n\nprogram ch2001\n ! Assumed Shape Parameter Passing\n use statistics_module\n implicit none\n\n integer, parameter :: n = 10\n real, dimension(1:n) :: x\n real, dimension(-4:5) :: y\n real, dimension(10) :: z\n real, dimension(:), allocatable :: t\n real :: m, sd\n integer :: i\n\n do i = 1, n\n x(i) = real(i)\n end do\n call stats(x,n,m,sd)\n print *, ' x'\n print 100, m, sd\n\n y = x\n call stats(y,n,m,sd)\n print *, ' y'\n print 100, m, sd\n\n z = x\n call stats(z,n,m,sd)\n print *, ' z'\n print 100, m, sd\n\n allocate(t(n))\n t = x\n call stats(t,n,m,sd)\n print *, ' t'\n print 100, m, sd\n\n100 format (' Mean = ', f7.3, ' Std Dev = ', f7.3)\nend program\n", "meta": {"hexsha": "7380f8967ab509c60fe73d314ddd9466cbbd3f7a", "size": 1321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch20/ch2001.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": "ch20/ch2001.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": "ch20/ch2001.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": 20.3230769231, "max_line_length": 50, "alphanum_fraction": 0.5132475397, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.8139939444307406}} {"text": "c square matrix multiplication\n program matmul\n integer n\n parameter (n=10)\n real*8 a(n,n), b(n,n), c(n,n)\n integer i, j, k\n do j=1, n\n do i=1, n\n a(i,j) = real(i-(n/2))/real(j)\n b(i,j) = real(j-3)/real(i)\n enddo\n enddo\nc\nc matrix multiply: C=A*B\nc\n do j=1, n\n do i=1, n\n c(i,j) = 0.\n do k=1, n\n c(i,j) = c(i,j) + a(i,k)*b(k,j)\n enddo\n enddo\n enddo\nc\nc again..\nc\n do j=1, n\n do i=1, n\n c(i,j) = 0.\n enddo\n enddo\n do k=1, n\n do j=1, n\n do i=1, n\n c(i,j) = c(i,j) + a(i,k)*b(k,j)\n enddo\n enddo\n enddo\nc\nc output of the result\nc\n print *, ((c(i,j), i=1, n), j=1, n)\n end\n!tps$ activate PRINT_CODE_PROPER_REDUCTIONS\n!tps$ display PRINTED_FILE\n!tps$ activate PRINT_CODE_CUMULATED_REDUCTIONS\n!tps$ display PRINTED_FILE\n", "meta": {"hexsha": "46e2463c88984c7c71bd47670cd72f8e872a75cc", "size": 968, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Reductions/mm.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/Reductions/mm.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/Reductions/mm.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": 20.1666666667, "max_line_length": 46, "alphanum_fraction": 0.4493801653, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.813991803804509}} {"text": "program hitmiss_mc_int\n ! Program to evaluate I= 0^3 exp(3)dx\n\n implicit none\n integer:: counter, nbins, npts_in_curve\n ! counter : counter variable\n ! nbins : number of bins\n ! npts_in_curve : number of points that lie within the region of\n ! interest\n\n real*8:: x, p, y, integral, actual_value\n ! x : varialbe storing random number of x-axis\n ! y : varialbe storing random number of y-axis\n ! p : dummy variable for the random number generator\n ! integral : value of the computed integral\n ! actual_value : Analytic value of the integral\n\n print *,\"Welcome to this program.&\n & This program does integration on I=0^3 exp(x)dx using Monte-Carlo Hit & Miss method on different number of bins (n) \" \n \n nbins=1\n actual_value=exp(3.0d0)-1\n 7 npts_in_curve=0\n open(unit=1, file=\"20181044_exp_accep_rej.dat\")\n write(*,10) nbins\n 10 format(\"Computing for nbins=\", i10)\n \n do counter=1,nbins\n ! find random value of \"x\" between 0 and 3\n call random_number(p)\n x=3.0d0*p\n\n ! find value of function between 0 and exp(3)\n call random_number(p)\n y=exp(3.0)*p\n\n ! If y at exp(x) is below the curve we accept the number\n if (y .lt. exp(x)) then\n npts_in_curve=npts_in_curve+1\n end if\n end do\n\n !multiply with area of rectangle and divide by the no. of cycles\n integral=3.0d0*exp(3.0)*(real(npts_in_curve)/real(nbins))\n write(1,*) nbins,\"\",integral,\"\",abs(integral-actual_value)\n\n ! automated\n nbins=nbins*10\n if (nbins .le. 100000000 ) goto 7\n print*, \"Done! Output stored in 20181044_exp_accep_rej.dat\"\n end program hitmiss_mc_int\n", "meta": {"hexsha": "7f3167e89011453a5467112b09f478e5bb0ccf00", "size": 1776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn02_solns/Assgn02_p2_hitmiss.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_hitmiss.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_hitmiss.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": 34.1538461538, "max_line_length": 129, "alphanum_fraction": 0.6216216216, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.81352952391572}} {"text": "module rosenbrock\n implicit none\n\ncontains\n function rosef(x)\n double precision, intent(in) :: x(:)\n double precision :: rosef\n\n double precision :: x1, x2\n double precision :: a, b\n\n x1 = x(1)\n x2 = x(2)\n\n a = (1 - x1)\n b = (x2 - x1*x1)\n\n rosef = a*a + 100*b*b\n end function rosef\n\n subroutine roseg(gx, x)\n double precision, intent(in) :: x(:)\n double precision, intent(out) :: gx(:)\n\n double precision :: x1, x2\n\n x1 = x(1)\n x2 = x(2)\n\n gx(1) = 400*x1*x1*x1 + 2*x1 -2 -400*x1*x2\n gx(2) = -200*x1*x1 + 200*x2\n end subroutine roseg\n\n subroutine roseh(hx, x)\n double precision, intent(in) :: x(:)\n double precision, intent(out) :: hx(:, :)\n\n double precision :: x1, x2\n\n x1 = x(1)\n x2 = x(2)\n\n hx(1, 1) = 1200*x1*x1 + 2 - 400*x2\n hx(1, 2) = -400*x1\n hx(2, 1) = -400*x1\n hx(2, 2) = 200\n end subroutine roseh\nend module rosenbrock\n", "meta": {"hexsha": "71d430aef0f9c943b136024cdbb01196154f6907", "size": 1039, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "EP/src/rosenbrock.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/rosenbrock.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/rosenbrock.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": 21.2040816327, "max_line_length": 49, "alphanum_fraction": 0.4841193455, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.8134231946274607}} {"text": "! Routine for cubic approximation\r\n! Igor Lopes, February 2015\r\nSUBROUTINE POLYCUBIC(NPOINT,X,F,XMIN,FMIN)\r\n IMPLICIT NONE\r\n REAL(8) R0 /0.0D0/\r\n REAL(8) R2 /2.0D0/\r\n REAL(8) R3 /3.0D0/\r\n REAL(8) SMALL /1.0D-8/\r\n ! Arguments\r\n INTEGER NPOINT\r\n REAL(8) :: XMIN, FMIN\r\n REAL(8),DIMENSION(4) :: X , F\r\n ! Locals\r\n REAL(8) :: A0,A1,A2,A3,Q1,Q2,Q3,Q4,Q5,Q6,XMAX,FMAX\r\n ! Begin algorithm\r\n IF(NPOINT.EQ.3)THEN\r\n Q1=(F(3)-F(1))/((X(3)-X(2))*(X(3)-X(1))**2)\r\n Q2=(F(2)-F(1))/((X(3)-X(2))*(X(2)-X(1))**2)\r\n Q3=F(4)/((X(3)-X(1))*(X(2)-X(1)))\r\n A3=Q1-Q2+Q3\r\n A2=((F(2)-F(1))/(X(2)-X(1))-F(4))/(X(2)-X(1))-A3*(R2*X(1)+X(2))\r\n A1=F(4)-R2*A2*X(1)-R3*A3*X(1)*X(1)\r\n A0=F(1)-A1*X(1)-A2*X(1)*X(1)-A3*X(1)*X(1)*X(1)\r\n ELSEIF(NPOINT.EQ.4)THEN\r\n Q1=X(3)**3*(X(2)-X(1))-X(2)**3*(X(3)-X(1))+X(1)**3*(X(3)-X(2))\r\n Q2=X(4)**3*(X(2)-X(1))-X(2)**3*(X(4)-X(1))+X(1)**3*(X(4)-X(2))\r\n Q3=(X(3)-X(2))*(X(2)-X(1))*(X(3)-X(1))\r\n Q4=(X(4)-X(2))*(X(2)-X(1))*(X(4)-X(1))\r\n Q5=F(3)*(X(2)-X(1))-F(2)*(X(3)-X(1))+F(1)*(X(3)-X(2))\r\n Q6=F(4)*(X(2)-X(1))-F(2)*(X(4)-X(1))+F(1)*(X(4)-X(2))\r\n A3=(Q3*Q6-Q4*Q5)/(Q2*Q3-Q1*Q4)\r\n A2=(Q5-A3*Q1)/Q3\r\n A1=(F(2)-F(1))/(X(2)-X(1))-A2*(X(1)+X(2))-A3*(X(2)**3-X(1)**3)/(X(2)-X(1))\r\n A0=F(1)-A1*X(1)-A2*X(1)*X(1)-A3*X(1)*X(1)*X(1)\r\n ELSE\r\n WRITE(*,*)'Wrong number of input points in POLYCUBIC'\r\n GOTO 99\r\n ENDIF\r\n WRITE(*,*)'Approximation coefficients:'\r\n WRITE(*,*)'a0=',A0\r\n WRITE(*,*)'a1=',A1\r\n WRITE(*,*)'a2=',A2\r\n WRITE(*,*)'a3=',A3\r\n WRITE(11,*)'Approximation coefficients:'\r\n WRITE(11,*)'a0=',A0\r\n WRITE(11,*)'a1=',A1\r\n WRITE(11,*)'a2=',A2\r\n WRITE(11,*)'a3=',A3\r\n ! Minimum or Maximum\r\n Q1=A2*A2-R3*A1*A3\r\n IF(Q1.LT.R0)THEN\r\n WRITE(*,*)'Unreal results'\r\n GOTO 99\r\n ELSEIF(Q1.LT.SMALL)THEN\r\n WRITE(*,*)'Neither minimum nor maximum is found'\r\n GOTO 99\r\n ENDIF\r\n XMIN=(-A2+DSQRT(Q1))/(R3*A3)\r\n FMIN=A0+A1*XMIN+A2*XMIN*XMIN+A3*XMIN**3\r\n XMAX=(-A2-DSQRT(Q1))/(R3*A3)\r\n FMAX=A0+A1*XMAX+A2*XMAX*XMAX+A3*XMAX**3\r\n WRITE(*,*)'A maximum is found for'\r\n WRITE(*,*)'X=',XMAX,'F_approx=',FMAX\r\n WRITE(*,*)'A minimum is found for'\r\n WRITE(*,*)'X=',XMIN,'F_approx=',FMIN\r\n WRITE(11,*)'A maximum is found for'\r\n WRITE(11,*)'X=',XMAX,'F_approx=',FMAX\r\n WRITE(11,*)'A minimum is found for'\r\n WRITE(11,*)'X=',XMIN,'F_approx=',FMIN\r\n99 CONTINUE \r\nEND SUBROUTINE", "meta": {"hexsha": "74b8ee069ee96222e0aa831fc67cd6f0bbfa31cf", "size": 2536, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/polynomial_approx/polycubic.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/polynomial_approx/polycubic.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/polynomial_approx/polycubic.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": 35.7183098592, "max_line_length": 83, "alphanum_fraction": 0.4802839117, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799482964025, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.813329185875288}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 2 - Series Computation\n!URN 6309823 - Penguin Lab Group 1K\n!March 10th 2015\n!--------------------------------------------------\n\n\n!A Taylor approximation will be produced which will look close to the actual function for the range of x values suggested\n!However there will be some noticeable deviations and the ends of the range.\n!This program, will output to a file called \"taylor.dat\".\n\n!Compile this program using the command gfortran\n\nPROGRAM Series_Computation\n\n IMPLICIT NONE\n REAL :: a,x,e,dx,pi,factorial\n INTEGER :: n,i,j,num\n\n OPEN(unit=20,file='taylor.dat')\n\n WRITE(6,*) \"This program will calculate the Taylor Series expansion of the function f(x)=sin(x)*exp(-x/2).\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"This describes an oscillation whose amplitude is exponentially decaying\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Specify the order (n) of the Taylor approximation\"\n !A reasonable value is 15\n READ(5,*) n\n WRITE(6,*) \" \"\n WRITE(6,*) \"Specify the number of x points\"\n !A reasonable value is 1000\n READ(5,*) num\n WRITE(6,*) \" \"\n \n pi=acos(-1.0)\n \n dx=4.0*pi/num \n \n !Where dx is the step value\n \n DO j=0,num\n e=0.0\n x=-2.0*pi+dx*j+1e-6\n a=sin(x)*exp(-x/2)\n factorial=1\n DO i=1,n\n\n !This DO loop calculates the taylor series values\n\n factorial=factorial*i\n e=((((-sqrt(5.0)/2.0)**i)*(sin(-i*atan(2.0))))/factorial)*x**i+e\n END DO \n WRITE (20,*) x,a,e\n \n !x is the values of the variable x\n !a is the value of produced by the original function\n !e is the value of each order of the taylor series\n\n END DO\n\n WRITE(6,*) \"The data is writen to the file taylor.dat in the format:\"\n WRITE(6,*) \"x, f(x), Taylor Expansion\"\n\n !Write in Terminal \"gnuplot\" then press ENTER\n !Write in Terminal \"plot \"taylor.dat\" using 1:2 w l, \"\" using 1:3 w l\" and press ENTER\n !Write in Terminal \"set yrange [-12,12]\" and press ENTER\n !Write in Terminal \"replot\" and press ENTER\n \nEND PROGRAM Series_Computation\n", "meta": {"hexsha": "64693a4a506db244269b52c8bc4222ef6fcee7d5", "size": 2054, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6309823-Series_Computation.f90", "max_stars_repo_name": "WilliamHoltam/computational-physics", "max_stars_repo_head_hexsha": "0c504766e356874e755971f5e82f76f6a367bc54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6309823-Series_Computation.f90", "max_issues_repo_name": "WilliamHoltam/computational-physics", "max_issues_repo_head_hexsha": "0c504766e356874e755971f5e82f76f6a367bc54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6309823-Series_Computation.f90", "max_forks_repo_name": "WilliamHoltam/computational-physics", "max_forks_repo_head_hexsha": "0c504766e356874e755971f5e82f76f6a367bc54", "max_forks_repo_licenses": ["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.9295774648, "max_line_length": 121, "alphanum_fraction": 0.6324245375, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.813088346528684}} {"text": "PROGRAM corio\n\n!*************************************\n!* Simulation of the Coriolis force \n!*\n!* Author: J. Kaempf, 2008\n!*************************************\n\nREAL :: u,v,un,vn,x,y,xn,yn\nREAL :: dt,fre,f,pi,alpha,beta\nINTEGER :: n,ntot,mode\n\n! initial speed and location\n\nu = 0.5\nv = 0.5\nx = 0.\ny = 5.\n\npi = 4.*atan(1.) ! this calculates Pi\nfreq = -2.*pi/(24.*3600.)\nf = 2*freq ! Coriolis parameter\ndt = 24.*3600./200. ! time step\n\n! parameters for semi-implicit scheme\nalpha = f*dt\nbeta = 0.25*alpha*alpha\n\nntot = 200; ! total number of interation steps\n\nmode = 1 ! choose between mode 1 and mode 2\n\nIF(mode == 1)THEN\n OPEN(10,FILE='output1.txt',FORM='formatted')\nELSE\n OPEN(10,FILE='output2.txt',FORM='formatted')\nEND IF\n\nWRITE(10,*)freq,dt,ntot\n\n!**** start of iteration loop ****\nDO n = 1,ntot\n!*********************************\n\ntime = REAL(n)*dt\n\n! velocity predictor\nIF (mode == 1) THEN\n un = (u*(1-beta)+alpha*v)/(1+beta)\n vn = (v*(1-beta)-alpha*u)/(1+beta)\nELSE\n un = cos(alpha)*u+sin(alpha)*v\n vn = cos(alpha)*v-sin(alpha)*u\nEND IF\n\n! predictor of new location\nxn = x + dt*un/1000\nyn = y + dt*vn/1000\n\n! updates for next time step \nu = un\nv = vn\nx = xn\ny = yn\n\n! data output\nWRITE(10,*)x,y,time\n\n!**** end of iteration loop ****\nEND DO\n!*******************************\n\nEND PROGRAM corio\n\n\n", "meta": {"hexsha": "7a3912c2766b0a66a4cee7c2a8748c4fcd96a9c7", "size": 1340, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "testcode/12_coriolis/code/Exercise 4/Coriolis.f95", "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/12_coriolis/code/Exercise 4/Coriolis.f95", "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/12_coriolis/code/Exercise 4/Coriolis.f95", "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": 17.6315789474, "max_line_length": 46, "alphanum_fraction": 0.552238806, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.8130163014366536}} {"text": "! Aditya Sengupta\n!! Conversion of temperature\n\nprogram temp_conversion\n\nimplicit none\n\nreal :: T_c, T_f, T_K\ncharacter :: input_unit\n\nprint*, \"Welcome to the Temperature Conversion Module !\"\n\nprint*, \"Input temperature in Celcius [C], Farheneit [F] or Kelvin [K] ?\"\n\nread*, input_unit\n\nif (input_unit == \"C\") then\n print*, \"Enter the temperature in Celcius\"\n read*, T_c\n T_f = ((9.0/5.0) * T_c) + 32.0 \n T_K = T_c + 273.0\n\n print*, \"You entered the temperature =\", T_c\n print*, \"temperature in Farheneit is =\", T_f\n print*, \"temperature in Kelvin is =\", T_K\n \nelse if (input_unit == \"F\") then\n print*, \"Enter the temperature in Farheneit\"\n read*, T_f\n T_c = (T_f - 32.0)*(5.0/9.0)\n T_K = T_c + 273.0\n\n print*, \"You entered the temperature =\", T_f\n print*, \"temperature in Celsius is =\", T_c\n print*, \"temperature in Kelvin is =\", T_K\n \nelse if (input_unit == \"K\") then\n\n print*, \"Enter the temperature in Kelvin\"\n read*, T_K\n T_c = T_K - 273.0\n T_f = ((9.0/5.0) * T_c) + 32.0\n\n print*, \"You entered the temperature =\", T_K\n print*, \"temperature in Celsius is =\", T_c\n print*, \"temperature in Farheneit is =\", T_f\n \nend if\n \nend program temp_conversion\n", "meta": {"hexsha": "e2579b706dd7f6acdad6a2bf0a846007ffef8f03", "size": 1228, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "practice/temp_conversion.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/temp_conversion.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/temp_conversion.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": 24.0784313725, "max_line_length": 73, "alphanum_fraction": 0.6254071661, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517061554854, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.8129098247086558}} {"text": "! Created by mus on 29/07/2021.\n! Recursive calculation of Legendre polynomials\n\nfunction legendrep(N,x) result(fac)\n !implicit none\n real (kind=8) :: fac\n real (kind=8), intent(in) :: x\n integer, intent(in) :: N\n real (kind=8), dimension(N+1) :: poly\n integer :: i\n\n select case (N)\n case (0)\n poly(1) = 1\n fac = poly(1)\n\n case (1)\n poly(2) = x\n fac = poly(2)\n\n case default\n poly(1) = 1\n poly(2) = x\n end select\n\n do i=3,N+1\n poly(i) = ((2*(i-1)-1)*x*poly(i-1) - (i-2)*poly(i-2))/(i-1)\n end do\n fac = poly(N+1)\nend function legendrep", "meta": {"hexsha": "c9f0fa28fc3dd588d371d42b466ad394d66c8273", "size": 638, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "legendrep.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": "legendrep.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": "legendrep.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": 21.2666666667, "max_line_length": 67, "alphanum_fraction": 0.5141065831, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811611608243, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.8126826227541594}} {"text": "\tFUNCTION qromb_sp(func,a,b,prec)\n\tuse mo_kind\n use mo_nrutil, ONLY : nrerror\n\tuse mo_nr, ONLY : polint,trapzd\n\tIMPLICIT NONE\n INTEGER(i4), INTENT(IN), optional :: prec\n\tREAL(SP), INTENT(IN) :: a,b\n\tREAL(SP) :: qromb_sp\n\tINTERFACE\n\t\tFUNCTION func(x)\n\t\tuse mo_kind\n\t\tREAL(SP), DIMENSION(:), INTENT(IN) :: x\n\t\tREAL(SP), DIMENSION(size(x)) :: func\n\t\tEND FUNCTION func\n\tEND INTERFACE\n\tINTEGER(I4), PARAMETER :: JMAX=20,JMAXP=JMAX+1,K=5,KM=K-1\n\tREAL(SP) :: EPS=1.0e-6_sp\n\tREAL(SP), DIMENSION(JMAXP) :: h,s\n\tREAL(SP) :: dqromb\n\tINTEGER(I4) :: j\n if ( present(prec) ) then\n EPS = 10._sp**(-prec)\n end if\n\th(1)=1.0\n\tdo j=1,JMAX\n\t\tcall trapzd(func,a,b,s(j),j)\n\t\tif (j >= K) then\n\t\t\tcall polint(h(j-KM:j),s(j-KM:j),0.0_sp,qromb_sp,dqromb)\n\t\t\tif (abs(dqromb) <= EPS*abs(qromb_sp)) RETURN\n\t\tend if\n\t\ts(j+1)=s(j)\n\t\th(j+1)=0.25_sp*h(j)\n\tend do\n\tcall nrerror('qromb_sp: too many steps')\n\tEND FUNCTION qromb_sp\n\n\tFUNCTION qromb_dp(func,a,b,prec)\n\tuse mo_kind\n use mo_nrutil, ONLY : nrerror\n\tuse mo_nr, ONLY : polint,trapzd\n\tIMPLICIT NONE\n INTEGER(i4), INTENT(in), optional :: prec\n\tREAL(DP), INTENT(IN) :: a,b\n\tREAL(DP) :: qromb_dp\n\tINTERFACE\n FUNCTION func(x)\n\t\tuse mo_kind\n\t\tREAL(DP), DIMENSION(:), INTENT(IN) :: x\n\t\tREAL(DP), DIMENSION(size(x)) :: func\n\t\tEND FUNCTION func\n\tEND INTERFACE\n\tINTEGER(I4), PARAMETER :: JMAX=20,JMAXP=JMAX+1,K=5,KM=K-1\n\tREAL(DP) :: EPS=1.0e-6_dp\n\tREAL(DP), DIMENSION(JMAXP) :: h,s\n\tREAL(DP) :: dqromb\n\tINTEGER(I4) :: j\n if ( present( prec ) ) then\n EPS= 10._dp**(-prec)\n end if\n\th(1)=1.0\n\tdo j=1,JMAX\n\t\tcall trapzd(func,a,b,s(j),j)\n\t\tif (j >= K) then\n\t\t\tcall polint(h(j-KM:j),s(j-KM:j),0.0_dp,qromb_dp,dqromb)\n\t\t\tif (abs(dqromb) <= EPS*abs(qromb_dp)) RETURN\n\t\tend if\n\t\ts(j+1)=s(j)\n\t\th(j+1)=0.25_dp*h(j)\n\tend do\n\tcall nrerror('qromb_dp: too many steps')\n\tEND FUNCTION qromb_dp\n\n", "meta": {"hexsha": "30e2261ebc2e7210cf34a23813145b9480be0585", "size": 1883, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/qromb.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/qromb.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/qromb.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": 25.7945205479, "max_line_length": 58, "alphanum_fraction": 0.6160382369, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8705972818382004, "lm_q1q2_score": 0.8126423300907369}} {"text": "! Calc Module\r\n\r\n module Calc\r\n use Util\r\n use Matrix\r\n implicit none\r\n integer :: INT_N = 128\r\n double precision :: h = 1.0D-5\r\n !double precision :: D_TOL = 1.0D-5\r\n\r\n character (len=*), parameter :: GAUSS_LEGENDRE_QUAD = \"quadratures/gauss-legendre/gauss-legendre\"\r\n character (len=*), parameter :: GAUSS_HERMITE_QUAD = \"quadratures/gauss-hermite/gauss-hermite\"\r\n contains\r\n! ================= Numerical Mathods =================\r\n function d(f, x, dx, kind) result (y)\r\n implicit none\r\n character (len=*), optional :: kind\r\n double precision, optional :: dx\r\n character (len=:), allocatable :: t_kind\r\n double precision :: x, y, t_dx\r\n \r\n interface\r\n function f(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(dx)) then\r\n t_dx = h\r\n else\r\n t_dx = dx\r\n end if\r\n\r\n if (.NOT. PRESENT(kind)) then\r\n t_kind = \"central\"\r\n else\r\n t_kind = kind\r\n end if\r\n\r\n if (t_kind == \"central\") then\r\n y = (f(x + t_dx) - f(x - t_dx)) / (2 * t_dx)\r\n else if (t_kind == \"forward\") then\r\n y = (f(x + t_dx) - f(x)) / t_dx\r\n else if (t_kind == \"backward\") then\r\n y = (f(x) - f(x - t_dx)) / t_dx\r\n else \r\n call error(\"Unexpected value `\"//t_kind//\" for derivative kind.\"// &\r\n \"Options are: `central`, `forward` and `backward`.\")\r\n end if\r\n return\r\n end function\r\n\r\n function dp(f, x, i, n) result (y)\r\n implicit none\r\n integer :: i, n\r\n double precision :: f\r\n double precision :: x(n), xh(n)\r\n double precision :: y\r\n\r\n xh(:) = 0.0D0\r\n xh(i) = h\r\n\r\n y = (f(x + xh) - f(x - xh)) / (2 * h)\r\n return\r\n end function\r\n\r\n function grad(f, x, n) result (y)\r\n implicit none\r\n integer :: i, n\r\n double precision :: f\r\n double precision :: xh(n), x(n), y(n)\r\n\r\n xh(:) = 0.0D0\r\n do i=1, n\r\n! Compute partial derivative with respect to x_i \r\n xh(i) = h\r\n y(i) = (f(x + xh) - f(x - xh)) / (2 * h)\r\n xh(i) = 0.0D0\r\n end do\r\n return\r\n end function\r\n\r\n! =====================================================\r\n\r\n function lagrange(x0, y0, n, x) result (y)\r\n implicit none\r\n integer :: n\r\n double precision :: x0(n), y0(n)\r\n double precision :: x, y, yi\r\n integer :: i, j\r\n\r\n y = 0.0D0\r\n do i = 1, n\r\n yi = y0(i)\r\n do j = 1, n\r\n if (i /= j) then\r\n yi = yi * (x - x0(j)) / (x0(i) - x0(j))\r\n end if\r\n end do\r\n y = y + yi\r\n end do\r\n\r\n return\r\n end function\r\n\r\n function bissection(f, aa, bb, tol) result (x)\r\n implicit none\r\n double precision, intent(in) :: aa, bb\r\n double precision :: a, b, x, t_tol\r\n double precision, optional :: tol\r\n\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n if (bb < aa) then\r\n a = bb\r\n b = aa\r\n else\r\n a = aa\r\n b = bb\r\n end if\r\n\r\n do while (DABS(a - b) > t_tol)\r\n x = (a + b) / 2\r\n if (f(a) > f(b)) then\r\n if (f(x) > 0) then\r\n a = x\r\n else\r\n b = x\r\n end if\r\n else \r\n if (f(x) < 0) then\r\n a = x\r\n else\r\n b = x\r\n end if\r\n end if\r\n end do\r\n x = (a + b) / 2\r\n return\r\n end function\r\n\r\n function newton(f, df, x0, ok, tol, max_iter) result (x)\r\n implicit none\r\n integer :: k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, intent(in) :: x0\r\n double precision :: x, xk, t_tol\r\n double precision, optional :: tol\r\n logical, intent(out) :: ok\r\n\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n interface\r\n function df(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n xk = x0\r\n do k = 1, t_max_iter\r\n x = xk - f(xk) / df(xk)\r\n if (DABS(x - xk) > t_tol) then\r\n xk = x\r\n else\r\n if (ISNAN(x) .OR. x == DINF .OR. x == DNINF) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if \r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function secant(f, x0, ok, tol, max_iter) result (x)\r\n implicit none\r\n integer :: k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision :: xk(3), yk(2)\r\n double precision, intent(in) :: x0\r\n double precision :: x, t_tol\r\n double precision, optional :: tol\r\n logical, intent(out) :: ok\r\n interface\r\n function f(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n xk(1) = x0\r\n xk(2) = x0 + h\r\n yk(1) = f(xk(1))\r\n do k = 1, t_max_iter\r\n yk(2) = f(xk(2))\r\n xk(3) = xk(2) - (yk(2) * (xk(2) - xk(1))) / (yk(2) - yk(1)) \r\n if (DABS(xk(3) - xk(2)) > t_tol) then\r\n xk(1:2) = xk(2:3)\r\n yk(1) = yk(2)\r\n else\r\n x = xk(3)\r\n if (ISNAN(x) .OR. x == DINF .OR. x == DNINF) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if \r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function inv_interp(f, x00, ok, tol, max_iter) result (x)\r\n implicit none\r\n logical, intent(out) :: ok\r\n integer :: i, j(1), k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision :: x, xk, t_tol\r\n double precision, optional :: tol\r\n double precision, intent(in) :: x00(3)\r\n double precision :: x0(3), y0(3)\r\n\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n x0(:) = x00(:)\r\n xk = 1.0D+308\r\n\r\n ok = .TRUE.\r\n\r\n do k = 1, t_max_iter\r\n call cross_sort(x0, y0, 3)\r\n\r\n! Cálculo de y \r\n do i = 1, 3\r\n y0(i) = f(x0(i))\r\n end do\r\n\r\n x = lagrange(y0, x0, 3, 0.0D0)\r\n\r\n if (DABS(x - xk) > t_tol) then\r\n j(:) = MAXLOC(DABS(y0))\r\n i = j(1)\r\n x0(i) = x\r\n y0(i) = f(x)\r\n xk = x\r\n else\r\n if (ISNAN(x) .OR. x == DINF .OR. x == DNINF) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function sys_newton(ff, dff, x0, n, ok, tol, max_iter) result (x)\r\n implicit none\r\n logical, intent(out) :: ok\r\n integer :: n, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, dimension(n), intent(in) :: x0\r\n double precision, dimension(n) :: x, xdx, dx\r\n double precision, dimension(n, n) :: J\r\n double precision :: t_tol\r\n double precision, optional :: tol\r\n \r\n interface\r\n function ff(x, n) result (y)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n), y(n)\r\n end function\r\n end interface\r\n\r\n interface\r\n function dff(x, n) result (J)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n), J(n, n)\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n x = x0\r\n\r\n do k=1, t_max_iter\r\n J = dff(x, n)\r\n dx = -MATMUL(inv(J, n, ok), ff(x, n))\r\n xdx = x + dx\r\n \r\n if (.NOT. ok) then\r\n exit\r\n else if ((NORM(dx, n) / NORM(xdx, n)) > t_tol) then\r\n x = xdx\r\n else\r\n if (VEDGE(x)) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function sys_newton_num(ff, x0, n, ok, tol, max_iter) result (x)\r\n! Same as previous function, with numerical partial derivatives \r\n implicit none\r\n logical, intent(out) :: ok\r\n integer :: n, i, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, dimension(n), intent(in) :: x0\r\n double precision, dimension(n):: x, xdx, xh, dx\r\n double precision, dimension(n, n) :: J\r\n double precision :: t_tol\r\n double precision, optional :: tol\r\n \r\n interface\r\n function ff(x, n) result (y)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n), y(n)\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n x = x0\r\n xh = 0.0D0\r\n\r\n do k=1, t_max_iter\r\n! Compute Jacobian Matrix\r\n do i=1, n\r\n! Partial derivative with respect do the i-th coordinates \r\n xh(i) = h\r\n J(:, i) = (ff(x + xh, n) - ff(x - xh, n)) / (2 * h)\r\n xh(i) = 0.0D0\r\n end do\r\n\r\n dx = -MATMUL(inv(J, n, ok), ff(x, n))\r\n xdx = x + dx\r\n\r\n if (.NOT. ok) then\r\n exit\r\n else if ((NORM(dx, n) / NORM(xdx, n)) > t_tol) then\r\n x = xdx\r\n else\r\n if (VEDGE(x)) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function sys_broyden(ff, x0, B0, n, ok, tol, max_iter) result (x)\r\n implicit none\r\n logical, intent(out) :: ok\r\n integer :: n, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, dimension(n), intent(in) :: x0\r\n double precision, dimension(n, n), intent(in) :: B0\r\n double precision, dimension(n) :: x, xdx, dx, dff\r\n double precision, dimension(n, n) :: J\r\n double precision :: t_tol\r\n double precision, optional :: tol\r\n\r\n interface\r\n function ff(x, n) result (y)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n), y(n)\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n x = x0\r\n J = B0\r\n\r\n do k=1, t_max_iter\r\n dx = -MATMUL(inv(J, n, ok), ff(x, n))\r\n if (.NOT. ok) then\r\n exit\r\n end if\r\n xdx = x + dx\r\n dff = ff(xdx, n) - ff(x, n)\r\n if ((norm(dx, n) / norm(xdx, n)) > t_tol) then\r\n J = J + OUTER_PRODUCT((dff - MATMUL(J, dx)) / DOT_PRODUCT(dx, dx), dx, n)\r\n x = xdx\r\n else\r\n if (VEDGE(x) .OR. (NORM(ff(x, n), n) > t_tol)) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function sys_least_squares(ff, dff, x, y, b0, m, n, ok, tol, max_iter) result (b)\r\n implicit none\r\n logical, intent(out) :: ok\r\n integer :: m, n, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, dimension(n), intent(in) :: x, y, b0\r\n double precision, dimension(n) :: b, bdb, db\r\n double precision :: J(n, n) \r\n double precision :: t_tol\r\n double precision, optional :: tol\r\n \r\n interface\r\n function ff(x, b, m, n) result (z)\r\n implicit none\r\n integer :: m, n\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(m), intent(in) :: b\r\n double precision, dimension(n) :: z\r\n end function\r\n end interface\r\n\r\n interface\r\n function dff(x, b, m, n) result (J)\r\n implicit none\r\n integer :: m, n\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(m), intent(in) :: b\r\n double precision, dimension(n, m) :: J\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n b = b0\r\n\r\n do k=1, t_max_iter\r\n J = dff(x, b, m, n)\r\n db = -MATMUL(inv(MATMUL(TRANSPOSE(J), J), n, ok), MATMUL(TRANSPOSE(J), ff(x, b, m, n) - y))\r\n bdb = b + db\r\n\r\n if (.NOT. ok) then\r\n exit\r\n else if ((NORM(db, m) / NORM(bdb, m)) > t_tol) then\r\n b = bdb\r\n else\r\n if (VEDGE(b) .OR. (NORM(ff(x, b, m, n) - y, n) > t_tol)) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function sys_least_squares_num(ff, x, y, b0, m, n, ok, tol, max_iter) result (b)\r\n! Same as previous function, with numerical partial derivatives\r\n implicit none\r\n integer :: m, n, i, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision, dimension(n), intent(in) :: x, y, b0\r\n double precision, dimension(n) :: b, bdb, db, bh\r\n double precision :: J(n, n) \r\n double precision :: t_tol\r\n double precision, optional :: tol\r\n\r\n logical, intent(out) :: ok\r\n interface\r\n function ff(x, b, m, n) result (z)\r\n implicit none\r\n integer :: m, n\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(m), intent(in) :: b\r\n double precision, dimension(n) :: z\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(max_iter)) then\r\n t_max_iter = D_MAX_ITER\r\n else\r\n t_max_iter = max_iter\r\n end if\r\n\r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n ok = .TRUE.\r\n\r\n bh = 0.0D0\r\n b = b0\r\n\r\n do k=1, t_max_iter\r\n! Compute Jacobian Matrix\r\n do i=1, m\r\n! Partial derivative with respect do the i-th coordinates \r\n bh(i) = h\r\n J(:, i) = (ff(x, b + bh, m, n) - ff(x, b - bh, m, n)) / (2 * h)\r\n bh(i) = 0.0D0\r\n end do\r\n db = -MATMUL(inv(MATMUL(TRANSPOSE(J), J), n, ok), MATMUL(TRANSPOSE(J), ff(x, b, m, n) - y))\r\n bdb = b + db\r\n\r\n if (.NOT. ok) then\r\n exit\r\n else if ((NORM(db, m) / NORM(bdb, m)) > t_tol) then\r\n b = bdb\r\n else\r\n if (VEDGE(b) .OR. (NORM(ff(x, b, m, n) - y, n) > t_tol)) then\r\n ok = .FALSE.\r\n end if\r\n return\r\n end if\r\n end do\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n! ============ Numerical Integration ========\r\n subroutine load_quad(x, w, k, fname)\r\n! Load Quadrature\r\n implicit none\r\n integer :: k, m, n\r\n character (len=*) :: fname\r\n double precision, dimension(k) :: x, w\r\n double precision, dimension(:, :), allocatable :: xw\r\n call read_matrix(fname, xw, m, n)\r\n if (n /= 2 .OR. m /= k) then\r\n call error(\"Invalid Matrix dimensions.\")\r\n stop \"ERROR\"\r\n end if\r\n x(:) = xw(:, 1)\r\n w(:) = xw(:, 2)\r\n deallocate(xw)\r\n end subroutine\r\n\r\n function num_int(f, a, b, n, kind) result (s)\r\n implicit none\r\n integer :: n\r\n character (len=*), optional :: kind\r\n double precision :: a, b, s\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(kind)) then\r\n kind = \"polynomial\"\r\n end if\r\n\r\n if (kind == \"polynomial\") then\r\n s = polynomial_int(f, a, b, n)\r\n else if (kind == \"gauss-legendre\") then\r\n s = gauss_legendre_int(f, a, b, n)\r\n else if (kind == \"gauss-hermite\") then\r\n s = gauss_hermite_int(f, a, b, n)\r\n else if (kind == \"romberg\") then\r\n s = romberg_int(f, a, b, n)\r\n else \r\n call error(\"Unknown integration kind `\"//kind//\".\"// &\r\n \"Available options are: `polynomial`, `gauss-legendre`, `gauss-hermite` and `romberg`.\")\r\n end if\r\n\r\n end function\r\n\r\n function polynomial_int(f, a, b, n) result (s)\r\n implicit none\r\n integer :: n, i\r\n double precision :: a, b, s\r\n double precision, dimension(n) :: x, y, w\r\n double precision, dimension(n, n) :: V\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n \r\n x(:) = ((b-a)/(n-1)) * (/ (i, i=0,n-1) /) + a\r\n y(:) = (/ ((b**i - a**i)/i, i=1, n) /)\r\n V(:, :) = vandermond_matrix(x, n)\r\n w(:) = solve(V, y, n)\r\n s = 0.0D0\r\n do i=1, n\r\n s = s + (w(i) * f(x(i)))\r\n end do\r\n return\r\n end function\r\n\r\n function gauss_legendre_int(f, a, b, n) result (s)\r\n implicit none\r\n integer, intent(in) :: n\r\n double precision, intent(in) :: a, b\r\n double precision :: s\r\n double precision, dimension(n) :: xx, ww\r\n integer :: k\r\n character(len=*), parameter :: fname = GAUSS_LEGENDRE_QUAD\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n call load_quad(xx, ww, n, fname//STR(n)//\".txt\")\r\n\r\n xx(:) = ((b - a) * xx(:) + (b + a)) / 2\r\n s = 0.0D0\r\n do k=1, n\r\n s = s + (ww(k) * f(xx(k)))\r\n end do\r\n s = s * ((b - a) / 2)\r\n return\r\n end function\r\n\r\n function gauss_hermite_int(f, a, b, n) result (s)\r\n implicit none\r\n integer, intent(in) :: n\r\n double precision, intent(in) :: a, b\r\n double precision :: s\r\n double precision, dimension(n) :: xx, ww\r\n integer :: k\r\n character(len=*), parameter :: fname = GAUSS_HERMITE_QUAD\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n\r\n call load_quad(xx, ww, n, fname//STR(n)//\".txt\")\r\n\r\n if (a /= DNINF .OR. b /= DINF) then\r\n call error(\"O Método de Gauss-Hermite deve ser usado no intervalo dos reais.\")\r\n stop\r\n end if\r\n \r\n s = 0.0D0\r\n do k=1, n\r\n s = s + (ww(k) * f(xx(k)))\r\n end do\r\n\r\n return\r\n end function\r\n\r\n recursive function adapt_int(f, a, b, n, tol, kind) result (s)\r\n implicit none\r\n integer :: n\r\n character (len=*), optional :: kind\r\n double precision, intent(in) :: a, b\r\n double precision :: p, q, e, r, s, t_tol\r\n double precision, optional :: tol\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n \r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n if (n > 1) then\r\n p = num_int(f, a, b, n / 2, kind = kind)\r\n q = num_int(f, a, b, n, kind = kind)\r\n e = DABS(p - q)\r\n if (e <= t_tol) then\r\n s = q\r\n else\r\n r = (b + a) / 2\r\n s = adapt_int(f, a, r, n, tol=t_tol, kind=kind) + adapt_int(f, r, b, n, tol=t_tol, kind=kind)\r\n end if\r\n return\r\n else\r\n s = 0.0D0\r\n return\r\n end if\r\n end function\r\n\r\n function romberg_int(f, a, b, n, tol) result (s)\r\n implicit none\r\n integer, intent(in) :: n\r\n double precision, intent(in) :: a, b\r\n double precision, optional :: tol\r\n interface\r\n function f(x) result (y)\r\n double precision :: x, y\r\n end function\r\n end interface\r\n integer :: i, j, k, t_n\r\n double precision :: s, dx, t_tol\r\n! Previous row, Current row and Temporary row \r\n double precision, dimension(:, :), allocatable :: R\r\n \r\n if (.NOT. PRESENT(tol)) then\r\n t_tol = D_TOL\r\n else\r\n t_tol = tol\r\n end if\r\n\r\n t_n = ILOG2(n)\r\n\r\n dx = (b - a)\r\n\r\n allocate(R(t_n + 1, t_n + 1))\r\n\r\n R(1, 1) = (f(a) + f(b)) * dx / 2\r\n\r\n do i = 1, t_n\r\n dx = dx / 2\r\n\r\n R(i + 1, 1) = (f(a) + 2 * SUM((/ (f(a + k*dx), k=1, (2**i)-1) /)) + f(b)) * dx / 2;\r\n\r\n do j = 1, i\r\n k = 4 ** j\r\n R(i + 1, j + 1) = (k*R(i + 1, j) - R(i, j)) / (k - 1)\r\n end do\r\n\r\n if (DABS(R(i + 1, i + 1) - R(i, i)) > t_tol) then\r\n continue\r\n else\r\n exit\r\n end if\r\n end do\r\n s = R(i, i)\r\n\r\n deallocate(R)\r\n end function\r\n\r\n function richard(f, x, p, q, dx, kind) result (y)\r\n! Richard Extrapolation\r\n implicit none\r\n double precision, optional :: dx, p, q\r\n character(len=*), optional :: kind\r\n double precision :: x, y, t_p, t_q, t_dx, dx1, dx2, d1, d2\r\n interface\r\n function f(x) result (y)\r\n implicit none\r\n double precision :: x, y\r\n end function\r\n end interface\r\n \r\n if (.NOT. PRESENT(dx)) then\r\n t_dx = h\r\n else\r\n t_dx = dx\r\n end if\r\n\r\n if (.NOT. PRESENT(p)) then\r\n t_p = 1.0D0\r\n else\r\n t_p = p\r\n end if\r\n\r\n if (.NOT. PRESENT(q)) then\r\n t_q = 2.0D0\r\n else\r\n t_q = q\r\n end if\r\n\r\n dx1 = t_dx\r\n d1 = d(f, x, dx1, kind = kind)\r\n dx2 = dx1 / t_q\r\n d2 = d(f, x, dx2, kind = kind)\r\n\r\n y = d1 + (d1 - d2) / ((t_q ** (-t_p)) - 1.0D0)\r\n return\r\n end function\r\n\r\n! ======== Ordinary Differential Equations ==========\r\n function ode_solve(df, y0, t, n, kind) result (y)\r\n implicit none\r\n integer :: n\r\n double precision, intent(in) :: y0\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n character(len=*), optional :: kind\r\n character(len=:), allocatable :: t_kind\r\n interface\r\n function df(t, y) result (u)\r\n implicit none\r\n double precision :: t, y, u\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(kind)) then\r\n t_kind = 'euler'\r\n else\r\n t_kind = kind\r\n end if\r\n\r\n if (t_kind == 'euler') then\r\n y = euler(df, y0, t, n)\r\n else if (t_kind == 'runge-kutta2') then\r\n y = runge_kutta2(df, y0, t, n)\r\n else if (t_kind == 'runge-kutta4') then\r\n y = runge_kutta4(df, y0, t, n)\r\n else\r\n call error(\"As opções são: `euler`, `runge-kutta2` e `runge-kutta4`.\")\r\n stop\r\n end if\r\n return\r\n end function\r\n\r\n\r\n function euler(df, y0, t, n) result (y)\r\n implicit none\r\n integer :: k, n\r\n double precision, intent(in) :: y0\r\n double precision :: dt\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n interface\r\n function df(t, y) result (u)\r\n implicit none\r\n double precision :: t, y, u\r\n end function\r\n end interface\r\n\r\n y(1) = y0\r\n do k=2, n\r\n dt = t(k) - t(k - 1)\r\n y(k) = y(k - 1) + df(t(k - 1), y(k - 1)) * dt\r\n end do\r\n return\r\n end function \r\n\r\n function runge_kutta2(df, y0, t, n) result (y)\r\n implicit none\r\n integer :: k, n\r\n double precision, intent(in) :: y0\r\n double precision :: k1, k2, dt\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n interface\r\n function df(t, y) result (u)\r\n implicit none\r\n double precision :: t, y, u\r\n end function\r\n end interface\r\n\r\n y(1) = y0\r\n do k=2, n\r\n dt = t(k) - t(k - 1)\r\n k1 = df(t(k - 1), y(k - 1))\r\n k2 = df(t(k - 1) + dt, y(k - 1) + k1 * dt)\r\n y(k) = y(k - 1) + dt * (k1 + k2) / 2\r\n end do\r\n return\r\n end function \r\n\r\n function runge_kutta4(df, y0, t, n) result (y)\r\n implicit none\r\n integer :: k, n\r\n double precision, intent(in) :: y0\r\n double precision :: k1, k2, k3, k4, dt\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n interface\r\n function df(t, y) result (u)\r\n implicit none\r\n double precision :: t, y, u\r\n end function\r\n end interface\r\n\r\n y(1) = y0\r\n do k=2, n\r\n dt = t(k) - t(k - 1)\r\n k1 = df(t(k - 1), y(k - 1))\r\n k2 = df(t(k - 1) + dt / 2, y(k - 1) + k1 * dt / 2)\r\n k3 = df(t(k - 1) + dt / 2, y(k - 1) + k2 * dt / 2)\r\n k4 = df(t(k - 1) + dt, y(k - 1) + dt * k3)\r\n y(k) = y(k - 1) + dt * (k1 + 2 * k2 + 2 * k3 + k4) / 6\r\n end do\r\n return\r\n end function\r\n\r\n function ode2_solve(d2f, y0, dy0, t, n, kind) result (y)\r\n implicit none\r\n integer :: n\r\n double precision, intent(in) :: y0, dy0\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n character(len=*), optional :: kind\r\n character(len=:), allocatable :: t_kind\r\n interface\r\n function d2f(t, y, dy) result (u)\r\n implicit none\r\n double precision :: t, y, dy, u\r\n end function\r\n end interface\r\n\r\n if (.NOT. PRESENT(kind)) then\r\n t_kind = 'taylor'\r\n else\r\n t_kind = kind\r\n end if\r\n\r\n if (t_kind == 'taylor') then\r\n y = taylor(d2f, y0, dy0, t, n)\r\n else if (t_kind == 'runge-kutta-nystrom') then\r\n y = runge_kutta_nystrom(d2f, y0, dy0, t, n)\r\n else\r\n call error(\"As opções são: `taylor`, `runge-kutta-nystrom`.\")\r\n stop\r\n end if\r\n return\r\n end function\r\n\r\n function taylor(d2f, y0, dy0, t, n) result (y)\r\n implicit none\r\n integer :: k, n\r\n double precision, intent(in) :: y0, dy0\r\n double precision :: dt, dy, d2y\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n interface\r\n function d2f(t, y, dy) result (d2y)\r\n implicit none\r\n double precision :: t, y, dy, d2y\r\n end function\r\n end interface\r\n! Solution\r\n y(1) = y0\r\n! 1st derivative\r\n dy = dy0\r\n do k=2, n\r\n dt = t(k) - t(k - 1)\r\n d2y = d2f(t(k - 1), y(k - 1), dy)\r\n y(k) = y(k - 1) + (dy * dt) + (d2y * dt ** 2) / 2\r\n dy = dy + d2y * dt\r\n end do\r\n return\r\n end function\r\n\r\n function runge_kutta_nystrom(d2f, y0, dy0, t, n) result (y)\r\n implicit none\r\n integer :: k, n\r\n double precision, intent(in) :: y0, dy0\r\n double precision :: k1, k2, k3, k4, dt, dy, l, q\r\n double precision, dimension(n), intent(in) :: t\r\n double precision, dimension(n) :: y\r\n interface\r\n function d2f(t, y, dy) result (u)\r\n implicit none\r\n double precision :: t, y, dy, u\r\n end function\r\n end interface\r\n\r\n y(1) = y0\r\n dy = dy0\r\n do k=2, n\r\n dt = t(k) - t(k - 1)\r\n k1 = (d2f(t(k - 1), y(k - 1), dy) * dt) / 2\r\n q = ((dy + k1 / 2) * dt) / 2\r\n k2 = (d2f(t(k - 1) + dt / 2, y(k - 1) + q, dy + k1) * dt) / 2\r\n k3 = (d2f(t(k - 1) + dt / 2, y(k - 1) + q, dy + k2) * dt) / 2\r\n l = (dy + k3) * dt\r\n k4 = (d2f(t(k - 1) + dt, y(k - 1) + l, dy + 2* k3) * dt) / 2\r\n\r\n y(k) = y(k - 1) + (dy + (k1 + k2 + k3) / 3) * dt\r\n dy = dy + (k1 + 2 * k2 + 2 * k3 + k4) / 3\r\n end do\r\n return\r\n end function\r\n end module Calc\r\n", "meta": {"hexsha": "3cdf6c4c403b11aeb121c17b54f3016d6f12d85f", "size": 34841, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/calclib.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/calclib.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/calclib.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": 32.2900834106, "max_line_length": 114, "alphanum_fraction": 0.3907178324, "num_tokens": 8720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.8125588712472728}} {"text": "submodule (stdlib_quadrature) stdlib_quadrature_gauss\n use stdlib_specialfunctions, only: legendre, dlegendre\n implicit none\n\n real(dp), parameter :: pi = acos(-1._dp)\n real(dp), parameter :: tolerance = 4._dp * epsilon(1._dp)\n integer, parameter :: newton_iters = 100\n\ncontains\n\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\n associate (n => size(x)-1 )\n select case (n)\n case (0)\n x = 0\n w = 2\n case (1)\n x(1) = -sqrt(1._dp/3._dp)\n x(2) = -x(1)\n w = 1\n case default\n block\n integer :: i,j\n real(dp) :: leg, dleg, delta\n\n do i = 0, (n+1)/2 - 1\n ! use Gauss-Chebyshev points as an initial guess\n x(i+1) = -cos((2*i+1)/(2._dp*n+2._dp) * pi)\n do j = 1, newton_iters\n leg = legendre(n+1,x(i+1))\n dleg = dlegendre(n+1,x(i+1))\n delta = -leg/dleg\n x(i+1) = x(i+1) + delta\n if ( abs(delta) <= tolerance * abs(x(i+1)) ) exit\n end do\n x(n-i+1) = -x(i+1)\n\n dleg = dlegendre(n+1,x(i+1))\n w(i+1) = 2._dp/((1-x(i+1)**2)*dleg**2) \n w(n-i+1) = w(i+1)\n end do\n\n if (mod(n,2) == 0) then\n x(n/2+1) = 0\n\n dleg = dlegendre(n+1, 0.0_dp)\n w(n/2+1) = 2._dp/(dleg**2) \n end if\n end block\n end select\n end associate\n\n if (present(interval)) then\n associate ( a => interval(1) , b => interval(2) )\n x = 0.5_dp*(b-a)*x+0.5_dp*(b+a)\n x(1) = interval(1)\n x(size(x)) = interval(2)\n w = 0.5_dp*(b-a)*w\n end associate\n end if\n end subroutine\n\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\n associate (n => size(x)-1)\n select case (n)\n case (1)\n x(1) = -1\n x(2) = 1\n w = 1\n case default\n block\n integer :: i,j\n real(dp) :: leg, dleg, delta\n\n x(1) = -1._dp\n x(n+1) = 1._dp\n w(1) = 2._dp/(n*(n+1._dp))\n w(n+1) = 2._dp/(n*(n+1._dp))\n\n do i = 1, (n+1)/2 - 1\n ! initial guess from an approximate form given by SV Parter (1999)\n x(i+1) = -cos( (i+0.25_dp)*pi/n - 3/(8*n*pi*(i+0.25_dp)))\n do j = 1, newton_iters\n leg = legendre(n+1,x(i+1)) - legendre(n-1,x(i+1))\n dleg = dlegendre(n+1,x(i+1)) - dlegendre(n-1,x(i+1))\n delta = -leg/dleg\n x(i+1) = x(i+1) + delta\n if ( abs(delta) <= tolerance * abs(x(i+1)) ) exit\n end do\n x(n-i+1) = -x(i+1)\n\n leg = legendre(n, x(i+1))\n w(i+1) = 2._dp/(n*(n+1._dp)*leg**2) \n w(n-i+1) = w(i+1)\n end do\n\n if (mod(n,2) == 0) then\n x(n/2+1) = 0\n\n leg = legendre(n, 0.0_dp)\n w(n/2+1) = 2._dp/(n*(n+1._dp)*leg**2) \n end if\n end block\n end select\n end associate\n \n if (present(interval)) then\n associate ( a => interval(1) , b => interval(2) )\n x = 0.5_dp*(b-a)*x+0.5_dp*(b+a)\n x(1) = interval(1)\n x(size(x)) = interval(2)\n w = 0.5_dp*(b-a)*w\n end associate\n end if\n end subroutine\nend submodule \n", "meta": {"hexsha": "0a346db486b157875e8dab64bd2a4c25990df47b", "size": 4125, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_quadrature_gauss.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_quadrature_gauss.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_quadrature_gauss.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": 33.5365853659, "max_line_length": 86, "alphanum_fraction": 0.3837575758, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.8124668953458171}} {"text": "MODULE INTERPOLATION \n INTERFACE LAGRANGE_INTERPOLATION\n MODULE PROCEDURE LAGRANGE\n MODULE PROCEDURE LAGRANGE_ARRAY\n END INTERFACE\n\n INTERFACE CUBIC_SPLINE_INTERPOLATION \n MODULE PROCEDURE CUBIC_SPLINE\n MODULE PROCEDURE CUBIC_SPLINE_ARRAY\n END INTERFACE CUBIC_SPLINE_INTERPOLATION \n\nCONTAINS \n\n !------------------------! \n ! Lagrange Interpolation ! \n !------------------------! \n FUNCTION LAGRANGE(x, t, y) \n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x\n REAL, DIMENSION(:), INTENT(IN) :: t, y\n REAL :: LAGRANGE\n\n REAL :: coefficient\n INTEGER :: j, k\n\n ! sanity check\n IF ( SIZE(t) /= SIZE(y) ) STOP 'Incompatible number of data between x and f(x)'\n \n ! initialization \n LAGRANGE = 0 \n \n ! loop through n data point \n DO j = 1, SIZE(t)\n coefficient = 1.0 \n\n ! kronecker delta\n DO k = 1, SIZE(t) \n IF ( k /= j ) & \n coefficient = coefficient * (x - t(k)) / (t(j) - t(k))\n END DO \n\n LAGRANGE = LAGRANGE + coefficient * y(j)\n END DO\n END FUNCTION LAGRANGE\n\n FUNCTION LAGRANGE_ARRAY(x, t, y)\n IMPLICIT NONE \n\n REAL, DIMENSION(:), INTENT(IN) :: x, t, y\n REAL, DIMENSION(SIZE(x)) :: LAGRANGE_ARRAY\n\n INTEGER :: i\n\n ! initialization \n LAGRANGE_ARRAY = 0 \n\n ! sanity check\n IF ( SIZE(t) /= SIZE(y) ) STOP 'Incompatible number of data between x and f(x)'\n\n DO i = 1, SIZE(x)\n LAGRANGE_ARRAY(i) = LAGRANGE(x(i), t, y)\n END DO\n END FUNCTION LAGRANGE_ARRAY\n\n !----------------------------! \n ! Cubic Spline Interpolation ! \n !----------------------------! \n FUNCTION CUBIC_SPLINE(x, t, y) \n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x \n REAL, DIMENSION(:), INTENT(IN) :: t, y\n REAL :: CUBIC_SPLINE\n\n REAL, DIMENSION(SIZE(t)) :: S2\n\n ! sanity check\n IF ( SIZE(t) /= SIZE(y) ) STOP 'Incompatible number of data between x and f(x)'\n\n ! solve for the set of second derivatives \n CALL CUBIC_SPLINE_INIT(t, y, S2)\n\n CUBIC_SPLINE = CUBIC_SPLINE_POLYNOMIAL(x, t, y, S2)\n END FUNCTION CUBIC_SPLINE\n\n FUNCTION CUBIC_SPLINE_ARRAY(x, t, y) \n IMPLICIT NONE \n\n REAL, DIMENSION(:), INTENT(IN) :: x, t, y\n REAL, DIMENSION(SIZE(x)) :: CUBIC_SPLINE_ARRAY\n\n REAL, DIMENSION(SIZE(t)) :: S2 \n INTEGER :: i\n\n ! sanity check\n IF ( SIZE(t) /= SIZE(y) ) STOP 'Incompatible number of data between x and f(x)'\n\n ! solve for the set of second derivatives \n CALL CUBIC_SPLINE_INIT(t, y, S2)\n\n DO i = 1, SIZE(x) \n CUBIC_SPLINE_ARRAY(i) = CUBIC_SPLINE_POLYNOMIAL(x(i), t, y, S2)\n END DO \n END FUNCTION CUBIC_SPLINE_ARRAY\n\n FUNCTION CUBIC_SPLINE_POLYNOMIAL(x, t, y, S2)\n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x\n REAL, DIMENSION(:), INTENT(IN) :: t, y\n REAL, DIMENSION(:), INTENT(IN) :: S2\n REAL :: CUBIC_SPLINE_POLYNOMIAL\n\n REAL :: h, A, B, C, D\n INTEGER :: i\n\n ! bracket x value \n i = CUBIC_SPLINE_INDEX(x, t) \n\n h = t(i+1) - t(i) \n A = S2(i+1) / (6 * h)\n B = S2(i) / (6 * h)\n C = y(i+1) / h - S2(i+1) * h / 6\n D = y(i) / h - S2(i) * h / 6\n\n CUBIC_SPLINE_POLYNOMIAL = & \n A * (x - t(i))**3 - B * (x - t(i+1))**3 + C * (x - t(i)) - D * (x - t(i+1))\n END FUNCTION CUBIC_SPLINE_POLYNOMIAL\n\n SUBROUTINE CUBIC_SPLINE_INIT(t, y, S2)\n IMPLICIT NONE \n\n REAL, DIMENSION(:), INTENT(IN) :: t, y\n REAL, DIMENSION(:), INTENT(OUT) :: S2 \n\n REAL, DIMENSION(SIZE(t)) :: beta\n REAL :: a_i, b_i, c_i, r_i\n INTEGER :: i \n\n ! natural spline\n ! this gives rise to a N-2 linear system of equations \n S2 = 0.0\n\n ! note: i = 2, N-1\n ! beta(1) and beta(N) is undefined because of boundary condition \n beta(2) = 2 * (t(3) - t(1))\n S2(2) = 6 * ((y(3) - y(2)) / (t(3) - t(2)) - (y(2) - y(1)) / (t(2) - t(1))) \n\n ! forward elimination \n DO i = 3, SIZE(t) - 1 \n ! off-diagonal term ( symmetric matrix A(i) = C(i-1) )\n a_i = t(i) - t(i-1) \n c_i = a_i\n\n ! diagonal term \n b_i = 2.0 * (t(i+1) - t(i-1))\n\n ! right-hand side \n r_i = 6.0 * ((y(i+1) - y(i)) / (t(i+1) - t(i)) - (y(i) - y(i-1)) / (t(i) - t(i-1)))\n\n ! eliminiation \n beta(i) = b_i - a_i * c_i / beta(i-1) \n S2(i) = r_i - a_i * S2(i-1) / beta(i-1)\n END DO \n\n ! backward substitution \n S2(SIZE(t) - 1) = S2(SIZE(t) - 1) / beta(SIZE(t) - 1)\n DO i = SIZE(t) - 2, 2, -1\n c_i = t(i+1) - t(i) \n S2(i) = (S2(i) - c_i * S2(i+1)) / beta(i) \n END DO \n END SUBROUTINE CUBIC_SPLINE_INIT\n\n FUNCTION CUBIC_SPLINE_INDEX(x, t)\n IMPLICIT NONE \n\n REAL, INTENT(IN) :: x\n REAL, DIMENSION(:), INTENT(IN) :: t\n INTEGER :: CUBIC_SPLINE_INDEX\n\n INTEGER :: a, b, m \n\n ! initialization \n ! preseving the index of t(:)\n a = 1\n b = SIZE(t)\n\n ! bisection \n DO WHILE ( (b - a) > 1 )\n ! ! mid point \n m = (a + b) / 2 \n IF ( x > t(m) ) THEN \n a = m \n ELSE \n b = m \n END IF\n END DO \n\n ! points at the boundaries \n IF ( x == t(a) ) THEN \n CUBIC_SPLINE_INDEX = 1 \n ELSE IF ( x == t(b) ) THEN \n CUBIC_SPLINE_INDEX = b-1\n ! otherwise lower bound \n ELSE \n CUBIC_SPLINE_INDEX = a \n END IF \n END FUNCTION CUBIC_SPLINE_INDEX\n\nEND MODULE INTERPOLATION \n", "meta": {"hexsha": "afaaf7231a109a4ab402aeaf94428fba2097575d", "size": 6297, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interpolation.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": "interpolation.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": "interpolation.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": 29.7028301887, "max_line_length": 95, "alphanum_fraction": 0.4487851358, "num_tokens": 1911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.8124668777077594}} {"text": "program trapezoidal_with_different_n\n ! Author : Anantha Rao (REg no: 20181044)\n ! Program to compute the Integral f(x) with different number of binsizes in powers of 5 \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,log_error, pi\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\n\n open(unit=1, file='20181044_trap_pi.dat')\n n = 1\n a = 0\n b = 1\n pi = 2.0d0*ASIN(1.0d0)\n ! write(*,*) \"Give the value of n\"\n ! read(*,*) n\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\n print *,\"Welcome to this program.&\n & This program does integration on I=0^1 4.0/(1+x^2) using trapezoidal rule different number of bins\"\n\n do\n n=n*5\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\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=4.0d0*(trap_summ+fa+fb)*h\n log_error=LOG(ABS(pi - trap_summ))\n write(1,*) LOG(real(n)),\"\",\"\",trap_summ,\"\",log_error\n if (n .ge. 1000000000) exit\n end do\n print*, \"Done!, Output stored in trap_pi.dat\"\n\nEND PROGRAM\n\nreal*8 function func(x)\n !evaluates f(x)=1/(1+x^2)\n implicit none\n real*8::x\n func=1.0d0/(1.0d0+x*x)\nend function\n\n", "meta": {"hexsha": "962a79b2ac234c1af50f6ddde8b2c391e258ac2f", "size": 1650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn01_solns/Assgn01_A_2_sourcecode.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/assgn01_solns/Assgn01_A_2_sourcecode.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/assgn01_solns/Assgn01_A_2_sourcecode.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": 25.78125, "max_line_length": 111, "alphanum_fraction": 0.5587878788, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.8740772269642948, "lm_q1q2_score": 0.812402692501538}} {"text": "c-----------------------------------------------------------------------\nc * This is fftlogtest.f\nc *\nc * This is a simple test program to illustrate how FFTLog works.\nc * The test transform is\nc * inf\nc * / mu+1 mu+1\nc * | r exp(-r^2/2) J_mu(k r) k dr = k exp(-k^2/2)\nc * /\nc * 0\nc *\nc * Disclaimer:\nc * FFTLog does NOT claim to provide the most accurate possible\nc * solution of the continuous transform (which is the stated aim\nc * of some other codes). Rather, FFTLog claims to solve the exact\nc * discrete transform of a logarithmically-spaced periodic sequence.\nc * If the periodic interval is wide enough, the resolution high\nc * enough, and the function well enough behaved outside the periodic\nc * interval, then FFTLog may yield a satisfactory approximation\nc * to the continuous transform.\nc *\nc * Observe:\nc * (1) How the result improves as the periodic interval is enlarged.\nc * With the normal FFT, one is not used to ranges orders of\nc * magnitude wide, but this is how FFTLog prefers it.\nc * (2) How the result improves as the resolution is increased.\nc * Because the function is rather smooth, modest resolution\nc * actually works quite well here.\nc * (3) That the central part of the transform is more reliable\nc * than the outer parts. Experience suggests that a good general\nc * strategy is to double the periodic interval over which the\nc * input function is defined, and then to discard the outer\nc * half of the transform.\nc * (4) That the best bias exponent seems to be q = 0.\nc * (5) That for the critical index mu = -1, the result seems to be\nc * offset by a constant from the `correct' answer.\nc * (6) That the result grows progressively worse as mu decreases\nc * below -1.\nc *\nc * The analytic integral above fails for mu <= -1, but FFTLog\nc * still returns answers. Namely, FFTLog returns the analytic\nc * continuation of the discrete transform. Because of ambiguity\nc * in the path of integration around poles, this analytic continuation\nc * is liable to differ, for mu <= -1, by a constant from the `correct'\nc * continuation given by the above equation.\nc *\nc * FFTLog begins to have serious difficulties with aliasing as\nc * mu decreases below -1, because then r^(mu+1) exp(-r^2/2) is\nc * far from resembling a periodic function.\nc * You might have thought that it would help to introduce a bias\nc * exponent q = mu, or perhaps q = mu+1, or more, to make the\nc * function a(r) = A(r) r^-q input to fhtq more nearly periodic.\nc * In practice a nonzero q makes things worse.\nc *\nc * A symmetry argument lends support to the notion that the best\nc * exponent here should be q = 0, as empirically appears to be true.\nc * The symmetry argument is that the function r^(mu+1) exp(-r^2/2)\nc * happens to be the same as its transform k^(mu+1) exp(-k^2/2).\nc * If the best bias exponent were q in the forward transform, then\nc * the best exponent would be -q that in the backward transform;\nc * but the two transforms happen to be the same in this case,\nc * suggesting q = -q, hence q = 0.\nc *\nc * This example illustrates that you cannot always tell just by\nc * looking at a function what the best bias exponent q should be.\nc * You also have to look at its transform. The best exponent q is,\nc * in a sense, the one that makes both the function and its transform\nc * look most nearly periodic.\nc *\nc parameters\n integer NMAX\n parameter (NMAX=4096)\nc externals\n integer lnblnk\nc local variables\n character*128 outfile\n integer dir,i,kropt,n,unit\n logical ok\n real*8 a(NMAX),dlnr,dlogr,k,kr,logkc,logrc,logrmax,logrmin,\n * mu,nc,q,r,rk\n real*8 wsave(2*NMAX+3*(NMAX/2)+19)\nc\n print *,'test integral_0^inf r^(mu+1) exp(-r^2/2) J_mu(k r) k dr =\n * k^(mu+1) exp(-k^2/2)'\nc--------reasonable choices of parameters\nc range of periodic interval\n logrmin=-4.d0\n logrmax=4.d0\nc number of points\n n=64\nc order of Bessel function\n mu=0.d0\nc bias exponent: q = 0 is unbiased\n q=0.d0\nc sensible approximate choice of k_c r_c\n kr=1.d0\nc tell fhti to change kr to low-ringing value\n kropt=3\nc forward transform\n dir=1\nc--------choose parameters\n 100 print *,'enter period range log10(r_min), log10(r_max) [',\n * logrmin,',',logrmax,']'\n read (*,*,end=300,err=300) logrmin,logrmax\nc central point log10(r_c) of periodic interval\n logrc=(logrmin+logrmax)/2.d0\n print *,'central point of periodic interval at log10(r_c) =',logrc\n print *,'enter number of points [',n,']'\n read (*,*,end=300,err=300) n\n if (n.gt.NMAX) then\n print *,n,' exceeds declared maximum',NMAX\n goto 100\n endif\nc central index (1/2 integral if n is even)\n nc=dble(n+1)/2.d0\nc log spacing of points\n dlogr=(logrmax-logrmin)/n\n dlnr=dlogr*log(10.d0)\nc order mu of Bessel function\n print *,'enter order mu of Bessel function [',mu,']'\n read (*,*,end=300,err=300) mu\nc bias exponent q\n print *,'enter bias exponent q [',q,']'\n read (*,*,end=300,err=300) q\nc kr = k_c r_c\n print *,'enter kr = k_c r_c [',kr,']'\n read (*,*,end=300,err=300) kr\nc--------r^(mu+1) exp(-r^2/2)\n do i=1,n\n r=10.d0**(logrc+(i-nc)*dlogr)\n a(i)=r**(mu+1.d0)*exp(-r**2/2.d0)\n enddo\nc--------initialize FFTLog transform - note fhti resets kr\n call fhti(n,mu,q,dlnr,kr,kropt,wsave,ok)\n if (.not.ok) goto 100\n logkc=log10(kr)-logrc\n print *,'central point in k-space at log10(k_c) =',logkc\nc rk = r_c/k_c\n rk=10.d0**(logrc-logkc)\nc--------transform\nc call fftl(n,a,rk,dir,wsave)\n call fht(n,a,dir,wsave)\nc--------print/write result\n print *,'enter name of file to save transform [CR=screen]'\n read (*,'(a128)') outfile\n if (outfile.eq.' ') then\n unit=6\n else\n unit=7\n open (unit,file=outfile)\n rewind (unit)\n endif\n write (unit,'(3a24)') 'k ','a(k) ','k^(mu+1) exp(-k^2/2)'\n do i=1,n\n k=10.d0**(logkc+(i-nc)*dlogr)\n write (unit,'(3g24.16)') k,a(i),k**(mu+1.d0)*exp(-k**2/2.d0)\n enddo\n call flush(unit)\n if (outfile.ne.' ') then\n print *,'header +',n,' lines written to file ',\n * outfile(1:lnblnk(outfile))\n endif\nc--------end of test loop\n goto 100\n 300 continue\n end\nc\n", "meta": {"hexsha": "a654416464b5c4c7b42ff27b9d5f7d934797c5cd", "size": 6512, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fftlogtest.f", "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": "fftlogtest.f", "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": "fftlogtest.f", "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": 38.7619047619, "max_line_length": 72, "alphanum_fraction": 0.6296068796, "num_tokens": 1937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.8123776994094056}} {"text": "!---------------------------------------------------------------------------------------------------\n!\n!\tfilename = base.f90\n!\tauthors = Edison Salazar\n!\t\t Pedro Guarderas\n!\tdate = 14/09/2013\n!\n!---------------------------------------------------------------------------------------------------\n\n\n!---------------------------------------------------------------------------------------------------\n! Module for base functions\nmodule base\n use consts\n implicit none\n\ncontains\n\n!---------------------------------------------------------------------------------------------------\n! Legendre polynomials\nsubroutine Legendre( x, P, N )\n implicit none\n integer i\n integer, intent( in ) :: N\n double precision, intent( in ) :: x\n double precision, intent( out ), dimension(0:N) :: P\n\n P(0) = 1.0\n P(1) = x\n do i = 1,N-1\n P(i+1) = ( ( 2.0D0 * dble(i) + 1.0D0 ) * x * P(i) - dble( i ) * P(i-1) ) / dble(i+1)\n end do\nend subroutine Legendre\n\n!---------------------------------------------------------------------------------------------------\n! Spherical harmonics Y_l type\nsubroutine SphHrm( Y, N, th, Nth )\n implicit none\n integer, intent( in ) :: N, Nth\n double precision, intent( in ) :: th(Nth)\n double precision, intent( out ), dimension(0:N,Nth) :: Y\n integer :: l, i\n double precision :: x\n\n !!$omp parallel do private(i)\n do i = 1,Nth\n x = cos(th(i))\n Y(0,i) = sqrt( 1.0D0 / pi4_ )\n Y(1,i) = sqrt( 3.0D0 / pi4_ ) * x\n do l = 1,N-1\n Y(l+1,i) = sqrt( ( 2.0D0 * l + 3.0D0 ) / pi4_ ) * ( &\n ( 2.0D0 * dble(l) + 1.0D0 ) * x * Y(l,i) - dble( l ) * Y(l-1,i) ) / dble(l+1)\n end do\n end do\nend subroutine SphHrm\n\n!---------------------------------------------------------------------------------------------------\n! Radial Hartree-Fock base function\nfunction STOradial( r, n, e ) result( rb )\n implicit none\n double precision, intent( in ) :: r, n, e\n double precision :: rb\n \n rb = ( 1.0D0 / sqrt( dgamma( 2.0D0 * n + 1.0D0 ) * ( 2.0D0 * e )**( -2.0D0 * n - 1.0D0 ) ) ) * &\n ( r**( n - 1.0D0 ) ) * exp( -e * r )\n\nend function STOradial\n\n!---------------------------------------------------------------------------------------------------\nfunction DrHFRb( r, n, e ) result( grb )\n implicit none\n double precision, intent( in ) :: r, n, e\n double precision :: grb\n \n grb = ( 1.0D0 / sqrt( dgamma( 2.0D0 * n + 1.0D0 ) * ( 2.0D0 * e )**( -2.0D0 * n - 1.0D0 ) ) ) * &\n ( ( n - 1.0D0 ) / r - e ) * ( r**( n - 1.0D0 ) ) * exp( -e * r )\n\nend function DrHFRb\n\nfunction STOnorm( n, e ) result( sltn )\n implicit none\n double precision, intent( in ) :: n, e\n double precision :: sltn\n\n! sltn = ( ( 2.0D0 * e )**n ) * sqrt( 2.0D0 * e / dgamma( 2.0D0 * n + 1 ) )\n sltn = dgamma( n + 1.0D0 ) * e**( -n - 1.0D0 )\n\nend function STOnorm\n\nend module base\n", "meta": {"hexsha": "f509437ba8b5ac0c8df0f9125d353de403c4b10d", "size": 2819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/base.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/base.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/base.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.978021978, "max_line_length": 100, "alphanum_fraction": 0.4114934374, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957912273285902, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.8122787212606711}} {"text": "PROGRAM F021\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAX_N = 10000 - 1\n\n INTEGER, DIMENSION(MAX_N) :: AMICABLE_NUMBERS = 0\n\n INTEGER :: PROPER_DIVISORS_SUM_1\n INTEGER :: PROPER_DIVISORS_SUM_2\n\n INTEGER :: I, J, N, J_MAX\n\n DO I = 2, MAX_N\n\n PROPER_DIVISORS_SUM_1 = 0\n PROPER_DIVISORS_SUM_2 = 0\n\n J_MAX = FLOOR(REAL(I) / 2.0)\n\n DO J = 1, J_MAX\n IF (MOD(I, J) == 0) PROPER_DIVISORS_SUM_1 = &\n PROPER_DIVISORS_SUM_1 + J\n END DO\n\n J_MAX = FLOOR(REAL(PROPER_DIVISORS_SUM_1) / 2.0)\n\n DO J = 1, J_MAX\n IF (MOD(PROPER_DIVISORS_SUM_1, J) == 0) PROPER_DIVISORS_SUM_2 = &\n PROPER_DIVISORS_SUM_2 + J\n END DO\n\n IF (I == PROPER_DIVISORS_SUM_2 .AND. I /= PROPER_DIVISORS_SUM_1) THEN\n AMICABLE_NUMBERS(I) = 1\n AMICABLE_NUMBERS(PROPER_DIVISORS_SUM_1) = 1\n END IF\n\n END DO\n\n N = 0\n DO I = 1, MAX_N\n N = N + (I * AMICABLE_NUMBERS(I))\n END DO\n\n PRINT ('(I0)'), N\n\nEND PROGRAM F021\n", "meta": {"hexsha": "76bfed03a9969de8dad9df9839ed8637588ad4c8", "size": 1175, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/021/021.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/021/021.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/021/021.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": 23.5, "max_line_length": 80, "alphanum_fraction": 0.5310638298, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.81200555741703}} {"text": "\tSUBROUTINE errorcalc(Nt,Nx,dt,c,x,u,err)\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This subroutine calculates the error in the approximate solution\n ! of the nonlinear Klein-Gordon equation 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 ! Nt = number of timesteps taken\n ! dt = timestep\n ! c = wavespeed\n\t! .. Vectors ..\n\t! x\t= x locations\n\t! u = solution at current timestep\n !\n\t! OUTPUT\n\t!\n\t! .. L2 norm of error ..\n\t! err = L2 norm of error\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\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\t:: Nx,Nt\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(IN) \t\t:: x\n\tREAL(KIND=8), DIMENSION(1:NX), INTENT(IN)\t\t:: u\n\tINTEGER(kind=4)\t\t\t\t\t\t:: i\n REAL(KIND=8), INTENT(IN) :: c,dt\n REAL(KIND=8) :: t\n REAL(KIND=8), INTENT(OUT) :: err\n t=REAL(Nt,kind=8)*dt\n err=0.0d0\n\t!$OMP PARALLEL DO PRIVATE(i) REDUCTION(+:err) SCHEDULE(static)\n\tDO i=1,Nx\n\t\terr=err+&\n (u(i)-sqrt(2.0d0)/(cosh((x(i)-c*t)/sqrt(1.0d0-c**2))) )**2\n ! err=err+&\n ! (u(i)-sqrt(2.0d0)/cosh(x(i)+t))**2\n\tEND DO\n\t!$OMP END PARALLEL DO\n PRINT *,'The final L2 error is ',sqrt(err/REAL(Nx,kind=8))\n\tEND SUBROUTINE errorcalc\n", "meta": {"hexsha": "776d834e7aed4b0eb36da61f9317dd95779c74c3", "size": 2062, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFiniteDifference8thOrderCompact/errorcalc.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/errorcalc.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/errorcalc.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": 28.6388888889, "max_line_length": 74, "alphanum_fraction": 0.51842871, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.8119726200047955}} {"text": "PROGRAM min_max\nIMPLICIT NONE\n REAL, EXTERNAL :: func_a, func_b\n REAL :: start, finish, xmin, ymin, xmax, ymax\n INTEGER :: steps\n WRITE(*, *) \"Enter start and end values:\"\n READ(*, *) start, finish\n WRITE(*, *) \"Enter the number of steps:\"\n READ(*, *) steps\n\n CALL find_min_max(start, finish, steps, func_a, xmin, ymin, xmax, ymax)\n WRITE(*, '(A,F10.4,A,F10.4)') \"func_a min: \", ymin, \" at \", xmin\n WRITE(*, '(A,F10.4,A,F10.4)') \"func_a max: \", ymax, \" at \", xmax\n CALL find_min_max(start, finish, steps, func_b, xmin, ymin, xmax, ymax)\n WRITE(*, '(A,F10.4,A,F10.4)') \"func_b min: \", ymin, \" at \", xmin\n WRITE(*, '(A,F10.4,A,F10.4)') \"func_b max: \", ymax, \" at \", xmax\nEND PROGRAM min_max\n\nSUBROUTINE find_min_max(first_val, last_val, num_steps, func, xmin, ymin, xmax, ymax)\nIMPLICIT NONE\n REAL, INTENT(IN) :: first_val, last_val\n INTEGER, INTENT(IN) :: num_steps\n REAL, EXTERNAL :: func\n REAL, INTENT(OUT) :: xmin, ymin, xmax, ymax\n REAL :: delta, x, y\n INTEGER :: i\n\n x = first_val\n y = func(x)\n xmin = x\n xmax = x\n ymin = y\n ymax = y\n delta = (last_val - first_val) / REAL(num_steps - 1)\n DO i = 1, num_steps - 1\n x = first_val + i * delta\n y = func(x)\n IF (y .le. ymin) THEN\n ymin = y\n xmin = x\n ELSE IF (y .ge. ymax) THEN\n ymax = y\n xmax = x\n END IF\n END DO\nEND SUBROUTINE find_min_max\n\nREAL FUNCTION func_a(r)\nIMPLICIT NONE\n REAL, INTENT(IN) :: r\n func_a = r**3 - 5 * r**2 + 5 * r + 2\nEND FUNCTION func_a\n\nREAL FUNCTION func_b(r)\nIMPLICIT NONE\n REAL, INTENT(IN) :: r\n func_b = r**2 / 2 - r\nEND FUNCTION func_b\n", "meta": {"hexsha": "b7dd0412b8dadb4408c6fac5333ba94cd392ca3b", "size": 1584, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/min_max.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/min_max.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/min_max.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.8474576271, "max_line_length": 85, "alphanum_fraction": 0.610479798, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.8118678171886852}} {"text": "! Computes an approximation of Pi with a Monte Carlo algorithm\n! Coarrays with final 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.f90 && time cafrun -n 4 ./a.out\n! or with ifort :\n! $ ifort -O3 -coarray pi_monte_carlo_coarrays.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) :: i ! Loop counter\n integer(int64) :: n_per_image ! Number of parallel images\n\n n = 1000000000\n k = 0\n\n call random_init(repeatable=.true., image_distinct=.true.)\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 end do\n\n ! At the end:\n call co_sum(k, result_image = 1)\n if (this_image() == 1) then\n write(*,*)\n write(*, '(a, i0, a, i0)') \"4 * \", k, \" / \", n\n write(*, '(a, f17.15)') \"Pi ~ \", (4.0_wp * k) / n\n end if\nend program pi_monte_carlo_coarrays_steady\n", "meta": {"hexsha": "0b1cc0ed37b09c14bea167c0995828d3bfa48cc1", "size": 1585, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi_monte_carlo_coarrays.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.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.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": 36.0227272727, "max_line_length": 102, "alphanum_fraction": 0.603785489, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.870597273444551, "lm_q1q2_score": 0.8117913132107137}} {"text": "program fibonacci_ite\n implicit none\n \n INTEGER :: A,B,S1,S2,i\n DOUBLE PRECISION :: start1, finish1, start2, finish2\n INTEGER :: C(0:1) !Defining an array ----> do not forget\n\n\n print*, 'Fibonacci s indice value for n = 50'\n write(*,'(/A)')\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !Variable iterative fibonacci \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n A = 0 \n B = 1\n S1 = 0\n\n call cpu_time(start1)\n do i = 1,45\n\n A = S1\n S1 = A + B\n B = A\n\n end do \n call cpu_time(finish1)\n\n print*,'Variable iterative fibonacci'\n print*, 'The number is: ',S1\n print*, finish1 - start1\n\n write(*,'(/A)')\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !Array iterative fibonacci \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n C(0) = 0\n C(1) = 1\n\n S2 = 0\n \n !print*, C !--> Just to be more clear\n\n call cpu_time(start2)\n do i = 1,45\n\n C(0) = S2\n S2 = sum(C)\n C(1) = C(0)\n\n end do\n call cpu_time(finish2)\n\n print*,'Array iterative fibonacci'\n print*, 'The number is: ',S2\n print *, finish2 - start2\n \n\nend program fibonacci_ite", "meta": {"hexsha": "9f4bcb2cbb3134b30766141199206a48fa7c0365", "size": 1119, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fibonacci's Sequence/Fortran/fibonacci_ite.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": "Fibonacci's Sequence/Fortran/fibonacci_ite.f90", "max_issues_repo_name": "arturofburgos/Comparing-Languages", "max_issues_repo_head_hexsha": "a20dc24699c762252c94c26e32c7053c04793d9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fibonacci's Sequence/Fortran/fibonacci_ite.f90", "max_forks_repo_name": "arturofburgos/Comparing-Languages", "max_forks_repo_head_hexsha": "a20dc24699c762252c94c26e32c7053c04793d9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-04T21:48:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-04T21:48:20.000Z", "avg_line_length": 18.0483870968, "max_line_length": 60, "alphanum_fraction": 0.471849866, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.8117912956478142}} {"text": "c**********************************************************************\nc This program calculates the value of pi, using numerical integration\nc with parallel processing. The user selects the number of points of\nc integration. By selecting more points you get more accurate results\nc at the expense of additional computation\nc \nc This version is written using p4 calls to handle message passing\nc It should run without changes on most workstation clusters and MPPs.\nc \nc Each node: \nc 1) receives the number of rectangles used in the approximation.\nc 2) calculates the areas of it's rectangles.\nc 3) Synchronizes for a global summation.\nc Node 0 prints the result.\nc \nc Constants:\nc \nc SIZETYPE initial message to the cube\nc ALLNODES used to load all nodes in cube with a node process\nc INTSIZ four bytes for an integer\nc DBLSIZ eight bytes for double precision\nc \nc Variables:\nc \nc pi the calculated result\nc n number of points of integration. \nc x midpoint of each rectangle's interval\nc f function to integrate\nc sum,pi area of rectangles\nc tmp temporary scratch space for global summation\nc i do loop index\nc****************************************************************************\n program main\n\n include 'mpif.h'\n\n double precision PI25DT\n parameter (PI25DT = 3.141592653589793238462643d0)\n\n integer INTSIZ , DBLSIZ, ALLNODES, ANYNODE\n parameter(INTSIZ=4,DBLSIZ=8,ALLNODES=-1,ANYNODE=-1)\n\n double precision pi, h, sum, x, f, a, temp\n integer n, myid, numnodes, i, rc\n integer sumtype, sizetype, masternode\n integer status(3)\n\nc 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, numnodes, ierr )\nc print *, \"Process \", myid, \" of \", numnodes, \" is alive\"\n\n sizetype = 10\n sumtype = 17\n masternode = 0\n \n 10 if ( myid .eq. 0 ) then\n\n write(6,98)\n 98 format('Enter the number of intervals: (0 quits)')\n read(5,99)n\n 99 format(i10)\n\n do i=1,numnodes-1\n call MPI_SEND(n,1,MPI_INTEGER,i,sizetype,MPI_COMM_WORLD,rc)\n enddo\n\n else\n \n call MPI_RECV(n,1,MPI_INTEGER,masternode,sizetype,\n + MPI_COMM_WORLD,status,rc)\n\n endif\n\nc check for quit signal\n if ( n .le. 0 ) goto 30\n\nc calculate the interval size\n h = 1.0d0/n\n\n sum = 0.0d0\n do 20 i = myid+1, n, numnodes\n x = h * (dble(i) - 0.5d0)\n sum = sum + f(x)\n 20 continue\n pi = h * sum\n\n if (myid .ne. 0) then\n\n call MPI_SEND(pi,1,MPI_DOUBLE_PRECISION,masternode,sumtype,\n + MPI_COMM_WORLD,rc)\n\n else\n\n do i=1,numnodes-1\n call MPI_RECV(temp,1,MPI_DOUBLE_PRECISION,i,sumtype,\n + MPI_COMM_WORLD,status,rc)\n pi = pi + temp\n enddo\n endif\n\nc node 0 prints the answer.\n if (myid .eq. 0) then\n write(6, 97) pi, abs(pi - PI25DT)\n 97 format(' pi is approximately: ', F18.16,\n + ' Error is: ', F18.16)\n endif\n\n goto 10\n\n 30 call MPI_FINALIZE(rc)\n end\n\n\n\n\n", "meta": {"hexsha": "6301e7a8a8c1d66c6b6db982db35e1deb5681e00", "size": 3419, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "papiex/tests/src/pi.f", "max_stars_repo_name": "tushar-mohan/papiex", "max_stars_repo_head_hexsha": "21a6ba029d64fb2d65174e510fb71ecaaea8c057", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-08-05T11:56:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:06:16.000Z", "max_issues_repo_path": "papiex/tests/src/pi.f", "max_issues_repo_name": "tushar-mohan/perftools", "max_issues_repo_head_hexsha": "21a6ba029d64fb2d65174e510fb71ecaaea8c057", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "papiex/tests/src/pi.f", "max_forks_repo_name": "tushar-mohan/perftools", "max_forks_repo_head_hexsha": "21a6ba029d64fb2d65174e510fb71ecaaea8c057", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-05T11:56:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T11:56:22.000Z", "avg_line_length": 28.4916666667, "max_line_length": 77, "alphanum_fraction": 0.5668324071, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.8117912893864644}} {"text": "real*8 function SHPowerL(c, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power at\n!\tdegree l corresponding to the spherical harmonic coefficients c(i, l, m)\n!\n!\tPower = Sum_{m=0}^l ( C1lm**2 + C2lm**2 )\n!\n!\tCalling Parameters\n!\t\tc\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\t\n\treal*8, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\n\t\n\tl1 = l+1\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < l1 .or. size(c(1,1,:)) < l1) then\n\t\tprint*, \"SHPowerL --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHPowerL = c(1, l1, 1)**2\t! m=0 term\n\t\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHPowerL = SHPowerL + c(i, l1, m1)**2\n\t\tenddo\n\tenddo\n\nend function SHPowerL\n\n\nreal*8 function SHPowerDensityL(c, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power per coefficient\n!\t(density) at degree l of the spherical harmonic coefficients c(i, l, m)\n!\n!\tPowerSpectralDensity = Sum_{m=0}^l ( C1lm**2 + C2lm**2 ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tc\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < l1 .or. size(c(1,1,:)) < l1) then\n\t\tprint*, \"SHPowerDensityL --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHPowerDensityL = c(1, l1, 1)**2\t! m=0 term\n\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHPowerDensityL = SHPowerDensityL + c(i, l1, m1)**2\n\t\tenddo\n\tenddo\n\t\n\tSHPowerDensityL = SHPowerDensityL/dble(2*l+1)\n\nend function SHPowerDensityL\n\n\nreal*8 function SHCrossPowerL(c1, c2, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power at\n!\tdegree l for the spherical harmonic coefficients c1(i, l, m)\n!\tand c2(i,l,m).\n!\n!\tCrossPower = Sum_{m=0}^l ( A1lm*B1lm + A2lm*B2lm )\n!\n!\tCalling Parameters\n!\t\tc1\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tc2\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < l1 .or. size(c1(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerL --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < l1 .or. size(c2(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerL --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHCrossPowerL = c1(1, l1, 1)*c2(1,l1,1)\n\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHCrossPowerL = SHCrossPowerL + c1(i, l1, m1)*c2(i,l1,m1)\n\t\tenddo\n\tenddo\n\nend function SHCrossPowerL\n\n\nreal*8 function SHCrossPowerDensityL(c1, c2, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power\n!\t(density) at degree l of the spherical harmonic coefficients c1(i, l, m)\n!\tand c2(i,l,m).\n!\n!\tCrossPower = Sum_{m=0}^l ( A1lm*B1lm + A2lm*B2lm ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tc1\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tc2\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < l1 .or. size(c1(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerDensityL --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < l1 .or. size(c2(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerDensityL --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHCrossPowerDensityL = c1(1, l1, 1)*c2(1,l1,1)\n\t\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHCrossPowerDensityL = SHCrossPowerDensityL + c1(i, l1, m1)*c2(i,l1,m1)\n\t\tenddo\n\tenddo\n\t\n\tSHCrossPowerDensityL = SHCrossPowerDensityL/dble(2*l+1)\n\nend function SHCrossPowerDensityL\n\n\nsubroutine SHPowerSpectrum(c, lmax, spectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power spectrum\n!\tof the spherical harmonic coefficients c(i, l, m).\n!\n!\tPower(l) = Sum_{m=0}^l ( C1lm**2 + C2lm**2 )\n!\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tspectra\tArray of length (lmax+1) containing the power\n!\t\t\t\tspectra of c.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < lmax+1 .or. size(c(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrum --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\telseif (size(spectra) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrum --- Error\"\n\t\tprint*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(spectra)\n\t\tstop\n\tendif\n\t\n\tspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tspectra(l1) = c(1, l1, 1)**2\n\t\t\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tspectra(l1) = spectra(l1) + c(i, l1, m1)**2\n\t\t\tenddo\n\t\tenddo\n\tenddo\n\nend subroutine SHPowerSpectrum\n\n\nsubroutine SHPowerSpectrumDensity(c, lmax, spectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power spectrum\n!\tdensity of the spherical harmonic coefficients c(i, l, m)\n!\n!\tPowerSpectralDensity = Sum_{m=0}^l ( C1lm**2 + C2lm**2 ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tspectra\tArray of length (lmax+1) containing the power\n!\t\t\t\tspectra density of c.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < lmax+1 .or. size(c(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumDensity --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\telseif (size(spectra) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumDensity --- Error\"\n\t\tprint*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(spectra)\n\t\tstop\n\tendif\n\n\tspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tspectra(l1) = c(1, l1, 1)**2\n\t\t\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tspectra(l1) = spectra(l1) + c(i, l1, m1)**2\n\t\t\tenddo\n\t\tenddo\n\t\t\n\t\tspectra(l1) = spectra(l1)/dble(2*l+1)\n\tenddo\n\nend subroutine SHPowerSpectrumDensity\n\n\nsubroutine SHCrossPowerSpectrum(c1, c2, lmax, cspectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power spectrum\n!\tof the spherical harmonic coefficients c1(i, l, m) and c2(1,l,m).\n!\n!\tCrossPower(l) = Sum_{m=0}^l ( A1lm*B1lm + A2lm*B2lm )\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc1\t\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tc2\t\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\t\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tcspectra\tArray of length (lmax+1) containing the cross power\n!\t\t\t\t\tspectra of c.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tcspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < lmax+1 .or. size(c1(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrum --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, LMAX+1, LMAX+1) where lmax is\", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < lmax+1 .or. size(c2(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrum --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\telseif (size(cspectra) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrum --- Error\"\n\t\tprint*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(cspectra)\n\t\tstop\n\tendif\n\n\tcspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\t cspectra(l1) = c1(1, l1, 1)*c2(1, l1, 1)\n\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tcspectra(l1) = cspectra(l1) + c1(i, l1, m1)*c2(i, l1, m1)\n\t\t\tenddo\n\t\tenddo\n\tenddo\n\nend subroutine SHCrossPowerSpectrum\n\n\nsubroutine SHCrossPowerSpectrumDensity(c1, c2, lmax, cspectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power spectrum\n!\tdensity of the spherical harmonic coefficients c1(i, l, m) and c2(i,l,m).\n!\n!\tCrossPower = Sum_{m=0}^l ( A1lm*B1lm + A2lm*B2lm ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc1\t\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tc2\t\tSpherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\t\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tcspectra\tArray of length (lmax+1) containing the cross power\n!\t\t\t\t\tspectral density of c.\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tcspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < lmax+1 .or. size(c1(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensity --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, LMAX+1, LMAX+1) where lmax is\", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < lmax+1 .or. size(c2(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensity --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\telseif (size(cspectra) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensity --- Error\"\n\t\tprint*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(cspectra)\n\t\tstop\n\tendif\n\n\tcspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tcspectra(l1) = c1(1, l1, 1)*c2(1, l1, 1)\n\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tcspectra(l1) = cspectra(l1) + c1(i, l1, m1)*c2(i, l1, m1)\n\t\t\tenddo\n\t\t\t\n\t\tenddo\n\t\t\n\t\tcspectra(l1) = cspectra(l1)/dble(2*l+1)\n\t\t\n\tenddo\n\nend subroutine SHCrossPowerSpectrumDensity\n\n", "meta": {"hexsha": "e8722dc7b82fcbbcd745f696751387386dab8abf", "size": 13605, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHPowerSpectra.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/SHPowerSpectra.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/SHPowerSpectra.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.4480519481, "max_line_length": 96, "alphanum_fraction": 0.5673649394, "num_tokens": 4969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.8116874929893423}} {"text": "\n! Subroutine to compute coefficients for linear regression with least squares method\n! Taken from Chapter 15 of:\n! Perrin, Charles L. Numerical Recipes in Fortran 90: The Art of Scientific Computing, \n! By William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery. \n! Cambridge University Press: New York, 1996. 1997.\n\n\nsubroutine LinRegLeastSquares(vector_x, & ! (I) Array of x data points \n vector_y, & ! (I) Array of y data points \n A_coeff, & ! (O) grade 0 coeff [-] \n B_coeff) ! (O) grade 1 coeff [-] \n \n \n implicit real(8) (a-h,o-z), integer(i-n)\n \n integer, parameter :: Ndatapoints = 40 \n \n real(8), dimension(Ndatapoints), intent(IN ) :: vector_x,vector_y\n real(8), intent( OUT) :: A_coeff,B_coeff\n \n real(8), dimension(Ndatapoints) :: SIG = 0.d0 ! Standard deviation of each point\n \n integer(8), parameter :: KWT = 0 ! [-] \n \n real(8):: CHI2,Q,SIGA,SIGB,SIGDAT, SS,ST2,Svector_x,SXOSS,Svector_y,T,WT\n \n \n ! Linear least square\n \n Svector_x=0.d0 !initialize sums to zero\n Svector_y=0.d0\n ST2=0.d0\n B_coeff=0.d0\n \n if (KWT .NE. 0.d0) then ! accumulate sums\n SS=0.d0\n do i=1,Ndatapoints\n WT=1.d0/(SIG(i)**2.d0) \n SS=SS+WT\n Svector_x=Svector_x+vector_x(i)*WT ! with weights\n Svector_y=Svector_y+vector_y(i)*WT\n end do \n else \n do i=1,Ndatapoints \n Svector_x=Svector_x+vector_x(i) ! without weights\n Svector_y=Svector_y+vector_y(i)\n end do \n SS=FLOAT(Ndatapoints) \n end if \n SXOSS= Svector_x/SS \n if (KWT .NE. 0.d0) then\n do i=1,Ndatapoints\n T=(Svector_x-SXOSS)/SIG(i)\n ST2=ST2+T*T\n B_coeff=B_coeff+vector_y(i)/SIG(i) \n end do \n else \n do i=1,Ndatapoints\n T=vector_x(i)-SXOSS\n ST2=ST2+T*T\n B_coeff=B_coeff+T*vector_y(i)\n end do \n end if\n B_coeff=B_coeff/ST2 ! solve for A,B\n A_coeff=(Svector_y-Svector_x*B_coeff)/SS\n SIGA=SQRT((1.d0+Svector_x*Svector_x/(SS*ST2))/SS)\n SIGB=SQRT(1.d0/ST2)\n CHI2=0.d0 ! calculate x^2\n Q=1.d0\n if(KWT .EQ. 0.d0) then\n do i=1,Ndatapoints\n CHI2=CHI2+(vector_y(i)-A_coeff-B_coeff*vector_x(i))**2.d0\n end do \n SIGDAT=SQRT(CHI2/(Ndatapoints-2.d0))\n SIGA=SIGA*SIGDAT\n SIGB=SIGB*SIGDAT\n else\n do i=1,Ndatapoints\n CHI2=CHI2+((vector_y(i)-A_coeff-B_coeff*vector_x(i))/SIG(i))**2.d0 \n end do \n Q=1.d0 \n end if\n\n return\n\nend subroutine LinRegLeastSquares \n", "meta": {"hexsha": "580519d3375fa8bba5dd12cee93bf5141cade70b", "size": 2959, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tools/linearregression.f90", "max_stars_repo_name": "pielube/MESS-Fortran", "max_stars_repo_head_hexsha": "bd9fcfdcd3990010714129533979ca0c015c026b", "max_stars_repo_licenses": ["MIT"], "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/tools/linearregression.f90", "max_issues_repo_name": "pielube/MESS-Fortran", "max_issues_repo_head_hexsha": "bd9fcfdcd3990010714129533979ca0c015c026b", "max_issues_repo_licenses": ["MIT"], "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/tools/linearregression.f90", "max_forks_repo_name": "pielube/MESS-Fortran", "max_forks_repo_head_hexsha": "bd9fcfdcd3990010714129533979ca0c015c026b", "max_forks_repo_licenses": ["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.625, "max_line_length": 88, "alphanum_fraction": 0.5221358567, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.8115680591192579}} {"text": "! Multiples of 3 and 5\n! Problem 1\n! If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n!\n! Find the sum of all the multiples of 3 or 5 below 1000.\n\n! Answer: 233168\n\nprogram ex001\n implicit none\n\n integer, parameter :: num = 1000\n integer :: i, res = 0\n \n do i = 1, num - 1\n if (mod(i, 3) == 0 .OR. mod(i, 5) == 0) res = res + i\n end do\n\n print *, 'Answer:', res\nend program ex001\n", "meta": {"hexsha": "f7c607a885917bf27c52d0f4cb50fdbdb46ed44e", "size": 479, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex001/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/ex001/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/ex001/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": 22.8095238095, "max_line_length": 131, "alphanum_fraction": 0.6200417537, "num_tokens": 175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574122783325, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.8115481965684318}} {"text": "! Test the FFFTW module: create a wave with specified frequencies and\n! write the input, output time-domain traces, plus the amplitude and phase.\nprogram test\n use FFFTW\n implicit none\n integer, parameter :: rs = 8\n integer, parameter :: npts = 2**11-1\n real(rs), parameter :: pi = 4._rs*atan2(1._rs, 1._rs)\n real(rs) :: t(npts), tval(npts), t_orig(npts)\n real(rs) :: dt, df, freq\n complex(rs) :: tc(npts), tc_orig(npts)\n complex(rs), allocatable :: f(:), fc(:)\n real(rs), allocatable :: fval(:), fvalc(:)\n integer :: i\n \n ! Sampling interval\n dt = 0.01_rs ! / seconds\n ! Frequency of sine wave\n freq = 2._rs ! / Hz\n \n ! Frequency sampling interval\n df = 1._rs/(dt*real(npts, kind=rs))\n \n ! Create signal for real and complex traces\n do i=1,npts\n t(i) = sin(2._rs*pi*real(i-1, kind=rs)*dt*freq) &\n + sin(2._rs*pi*real(i-1,rs)*dt*freq*2._rs)\n enddo\n ! Normalise amplitdue to ±1\n t = t/maxval(abs(t))\n tc = cmplx(t,-t, kind=rs)\n t_orig = t\n tc_orig = tc\n \n ! Write out original signal: real\n open(10,file=\"input_real.xy\")\n write(10,'(e12.6,1x,e12.6)') (real(i-1,rs)*dt,t(i), i=1,size(t))\n close(10)\n ! Complex\n open(10,file=\"input_complex.xy\")\n write(10,'(e12.6,1x,e12.6,1x,e12.6)') (real(i-1,rs)*dt,real(tc(i)),aimag(tc(i)), i=1,size(t))\n close(10)\n \n ! Create Fourier-transformed trace\n call FFFTW_fwd(t,f)\n call FFFTW_fwd(tc,fc)\n \n ! Allocate memory for frequency values\n allocate(fval(size(f)), fvalc(size(fc)))\n \n ! Fill in time and frequency values\n tval = [(real(i-1,rs)*dt, i=1,size(t))]\n fval = [(real(i-1,rs)*df, i=1,size(fval))]\n fvalc = [(real(i-1,rs)*df, i=1,size(fvalc))]\n \n ! Low-pass inf.-order filter in FD\n! where (fval > 3.0_rs)\n! f = complex(0._rs,0_rs)\n! end where\n \n ! Write out amplitude spectrum of FFT\n ! Real-to-complex\n open(10,file=\"amplitude_real.xy\")\n write(10,'(e12.6,1x,e12.6)') (fval(i),abs(f(i)), i=1,size(f))\n close(10)\n ! Phase\n open(10,file=\"phase_real.xy\")\n write(10,'(e12.6,1x,e12.6)') (fval(i),atan2(real(f(i)),aimag(f(i))), i=1,size(f))\n close(10)\n ! Complex-to-complex\n open(10,file=\"amplitude_complex.xy\")\n write(10,'(e12.6,1x,e12.6)') (fvalc(i),abs(fc(i)), i=1,size(fc))\n close(10)\n ! Phase\n open(10,file=\"phase_complex.xy\")\n write(10,'(e12.6,1x,e12.6)') (fvalc(i),atan2(real(fc(i)),aimag(fc(i))), i=1,size(fc))\n close(10)\n \n ! Create inverse trace\n call FFFTW_rev(f,t)\n call FFFTW_rev(fc,tc)\n \n ! Write out FFT-iFFT trace: real\n open(10,file=\"output_real.xy\")\n write(10,'(e12.6,1x,e12.6)') (tval(i),t(i), i=1,size(t))\n close(10)\n \n ! Write out difference between input and output: real\n open(10,file=\"output-input_real.xy\")\n write(10,'(e12.6,1x,e12.6)') (tval(i),abs(t(i)-t_orig(i)), i=1,size(t))\n close(10)\n \n write(*,'(a,e12.6)') 'Real: Average residual between input and output traces: ', &\n sum(abs(t-t_orig))/size(t)\n write(*,'(a,e12.6)') 'Real: Maximum residual between input and output traces: ', &\n maxval(abs(t-t_orig))\n \n ! Write out FFT-iFFT trace: complex\n open(10,file=\"output_complex.xy\")\n write(10,'(e12.6,1x,e12.6,1x,e12.6)') (tval(i),real(tc(i)),aimag(tc(i)), i=1,size(tc))\n close(10)\n\n ! Write out difference between input and output: complex\n open(10,file=\"output-input_complex.xy\")\n write(10,'(e12.6,1x,e12.6)') (tval(i),abs(tc(i)-tc_orig(i)), i=1,size(tc))\n close(10)\n\n write(*,'(a,e12.6)') 'Complex: Average residual between input and output traces: ', &\n sum(abs(tc-tc_orig))/size(tc)\n write(*,'(a,e12.6)') 'Complex: Maximum residual between input and output traces: ', &\n maxval(abs(tc-tc_orig))\n \n \nend program\n", "meta": {"hexsha": "9b505f3e7d5f014a315ede2366273c9b9b3dc980", "size": 3726, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "FFFTW/test_FFFTW/test_FFFTW.f03", "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": "FFFTW/test_FFFTW/test_FFFTW.f03", "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": "FFFTW/test_FFFTW/test_FFFTW.f03", "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": 32.4, "max_line_length": 96, "alphanum_fraction": 0.6081588835, "num_tokens": 1329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8115133052979198}} {"text": "! A physical or mathematical constant such as pi that will be used \r\n! in many parts of a program should be defined as a PARAMETER in a \r\n! module that is USEd where needed. In the code below pi is used both in \r\n! module m and the main program. One should declare a module\r\n! PRIVATE and list as PUBLIC the entities that will be referenced\r\n! outside the module. Module entities are public by default.\r\n!\r\nmodule constants_mod\r\nimplicit none\r\nprivate\r\npublic :: pi\r\nreal, parameter :: pi = 3.14159\r\nend module constants_mod\r\n!\r\nmodule m\r\nuse constants_mod, only: pi\r\nimplicit none\r\nprivate\r\npublic :: area_circle\r\ncontains\r\npure elemental function area_circle(radius) result(area)\r\nreal, intent(in) :: radius\r\nreal :: area\r\narea = pi*radius**2\r\nend function area_circle\r\nend module m\r\n!\r\nprogram main\r\nuse constants_mod, only: pi\r\nuse m , only: area_circle\r\nimplicit none\r\nreal, parameter :: radius = 10.0\r\nprint*,\"circumference, area =\",2*pi*radius,area_circle(radius)\r\n! output: circumference, area = 62.8318024 314.158997\r\nend program main\r\n", "meta": {"hexsha": "1f7ada857b015d5f1034d0c55f9ec2a23153e219", "size": 1077, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "module_parameter.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": "module_parameter.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": "module_parameter.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": 29.9166666667, "max_line_length": 74, "alphanum_fraction": 0.721448468, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.8115010074632519}} {"text": "!! Writing the functions factorial, permutation and combination\n\n! factorial\nrecursive integer*8 function fact(n) result(fact1) ! integer*8 and kind=8 is same\n\n implicit none\n integer*8, INTENT(IN) :: n\n\n if (n == 1 .or. n == 0) then\n fact1 = 1\n RETURN\n else\n fact1 = fact(n-1)\n fact1 = fact1*n\n RETURN\n end if\n\nend function fact\n\n! permutation\ninteger*8 function per(n,r)\n implicit none\n integer*8, INTENT(IN) :: n,r\n integer*8, external :: fact\n\n per = fact(n)/fact(n-r)\n\nend function per\n\n! combination\ninteger*8 function comm(n,r)\n implicit none\n integer*8, INTENT(IN) :: n,r\n integer*8, external :: fact\n\n comm = fact(n)/(fact(r) * fact(n-r))\n\nend function comm\n\n! second combination\ninteger*8 function com(per,r)\n implicit none\n integer*8, INTENT(IN) :: per, r\n integer*8, external :: fact\n\n com = per/fact(r)\nend function com\n\n! third combination\ninteger*8 function comb(n,r)\n implicit none\n integer*8, INTENT(IN) :: n, r\n integer*8, external :: fact, per\n\n comb = per(n,r)/fact(r)\nend function comb\n", "meta": {"hexsha": "8b62828b65789d3ef2ff4d09f3c5fe43d9e2ccef", "size": 1105, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran_tut/recursive_func/functions.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": "fortran_tut/recursive_func/functions.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": "fortran_tut/recursive_func/functions.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": 19.3859649123, "max_line_length": 81, "alphanum_fraction": 0.628959276, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338046748207, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.8114336611556702}} {"text": "module forlab_math\n\n use stdlib_kinds, only: sp, dp, qp, int8, int16, int32, int64\n use stdlib_optval, only: optval\n use stdlib_math, only: arange, is_close, all_close\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 !> `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": "242d54b3e8bfe2f52512e39b3bdac4a796065e7b", "size": 6313, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_math.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.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.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": 34.3097826087, "max_line_length": 78, "alphanum_fraction": 0.5993980675, "num_tokens": 1537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542887603537, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.8113893186515033}} {"text": "program test\n !! Program to show the usage of the *linear_solvers* module\n use linear_solvers\n implicit none\n\n integer, parameter :: N = 500\n real:: ti, tf\n\n real :: A(N,N), b(N), x_G(N), x_LU(N), x_J(N), x_GS(N), x_0(N)\n integer :: i, u, Nmax\n b = 0\n b(N) = -1.\n A = 0.\n do i = 1,N-1\n A(i,i+1) = 1.\n A(i,i) = -2.\n A(i+1,i) = 1.\n end do\n A(N,N) = -2\n\n call CPU_TIME(ti)\n x_G = gauss_solve(A,b)\n call CPU_TIME(tf)\n\n print*, 'Gauss'\n print'(3(A,1x,f9.6,A))', 'x =', x_G(1), NEW_LINE('a'), 'y =', x_G(2),NEW_LINE('a'), 'z =', x_G(3), NEW_LINE('a')\n print'(A,1x,I6,1x,A)', 'in', floor((tf -ti)*1E3), 'miliseconds'\n\n\n call CPU_TIME(ti)\n x_LU = solve(A,b)\n call CPU_TIME(tf)\n\n\n print*, 'LU'\n print'(3(A,1x,f9.6,A))', 'x =', x_LU(1), NEW_LINE('a'), 'y =', x_LU(2),NEW_LINE('a'), 'z =', x_LU(3), NEW_LINE('a')\n print'(A,1x,I6,1x,A)', 'in', floor((tf -ti)*1E3), 'miliseconds'\n\n\n Nmax = 100000\n\n ! x_0 = 0.5\n x_0(1:N/2) = 0.25\n x_0(N/2+1:N) = 0.75\n\n call CPU_TIME(ti)\n x_J = Jacobi(A,b, x_0, Nmax, 0.0001)\n call CPU_TIME(tf)\n\n print*, 'Jacobi'\n print'(3(A,1x,f9.6,A))', 'x =', x_J(1), NEW_LINE('a'), 'y =', x_J(2),NEW_LINE('a'), 'z =', x_J(3), NEW_LINE('a')\n print'(A,1x,I6,1x,A)', 'in', floor((tf -ti)*1E3), 'miliseconds'\n\n\n call CPU_TIME(ti)\n x_GS = GaussSeidel(A,b, x_0, Nmax, 0.0001)\n call CPU_TIME(tf)\n\n print*, 'Gauss-Seidel'\n print'(3(A,1x,f9.6,A))', 'x =', x_GS(1), NEW_LINE('a'), 'y =', x_GS(2),NEW_LINE('a'), 'z =', x_GS(3), NEW_LINE('a')\n print'(A,1x,I6,1x,A)', 'in', floor((tf -ti)*1E3), 'miliseconds'\n\n open(file='test.dat',newunit=u, action='write', status='unknown')\n do i = 1,N\n write(u,*) x_G(i), x_LU(i), x_J(i), x_GS(i)\n end do\n close(u)\nend program\n", "meta": {"hexsha": "5e35ad0ce4a2ff481d07b3ebeecaca6c9b2329de", "size": 1720, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/test_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": "src/test_linear_solvers.f90", "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/test_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": 24.9275362319, "max_line_length": 118, "alphanum_fraction": 0.5453488372, "num_tokens": 779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250325, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.8112447447336187}} {"text": "PROGRAM roots_2\r\n!\r\n! Purpose:\r\n! To find the roots of a quadratic equation \r\n! A * X**2 + B * X + C = 0.\r\n! using complex numbers to eliminate the need to branch \r\n! based on the value of the discriminant. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/01/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare variable types & definitions\r\nREAL :: a ! The coefficient of X**2\r\nREAL :: b ! The coefficient of X\r\nREAL :: c ! The constant coefficient\r\nREAL :: discriminant ! The discriminant of the quadratic eqn\r\nCOMPLEX :: x1 ! First solution to the equation\r\nCOMPLEX :: x2 ! Second solution to the equation\r\n \r\n! Get the coefficients.\r\nWRITE (*,1000) \r\n1000 FORMAT (' Program to solve for the roots of a quadratic', &\r\n /,' equation of the form A * X**2 + B * X + C = 0. ' )\r\nWRITE (*,1010) \r\n1010 FORMAT (' Enter the coefficients A, B, and C: ')\r\nREAD (*,*) a, b, c\r\n \r\n! Calculate the discriminant \r\ndiscriminant = b**2 - 4. * a * c\r\n \r\n! Calculate the roots of the equation\r\nx1 = ( -b + SQRT( CMPLX(discriminant,0.) ) ) / (2. * a)\r\nx2 = ( -b - SQRT( CMPLX(discriminant,0.) ) ) / (2. * a)\r\n \r\n! Tell user.\r\nWRITE (*,*) 'The roots are: '\r\nWRITE (*,1020) ' x1 = ', REAL(x1), ' + i ', AIMAG(x1)\r\nWRITE (*,1020) ' x2 = ', REAL(x2), ' + i ', AIMAG(x2)\r\n1020 FORMAT (A,F10.4,A,F10.4)\r\n \r\nEND PROGRAM roots_2\r\n", "meta": {"hexsha": "580422a58e5b762dd50f94a6138152467b800a4d", "size": 1552, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/roots_2.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/roots_2.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/roots_2.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.7391304348, "max_line_length": 66, "alphanum_fraction": 0.5476804124, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995762509216, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.8110986874121715}} {"text": " \tProgram oscillator\r\n \tImplicit none\r\nc declarations\r\nc n: number of equations, min/max in x, dist:length of x-steps\r\nc y(1): initial position, y(2):initial velocity\r\n\tReal*8 dist, min, max, x, y(5)\r\n\tInteger\tn\r\n\tn=2\r\n min=0.0\t\r\n max=10.0\r\n dist=0.1\r\n y(1)=1.0\r\n y(2)=0.0\r\nc open file\r\n Open(6, File='rk4.dat', Status='Unknown')\r\nc do n steps of Runga-Kutta algorithm\r\n\tDo 60 x=min, max, dist\r\n\tCall rk4(x, dist, y, n)\r\n Write (6,*) x, y(1)\r\n 60\tContinue\r\nc\r\n\tClose(6)\r\n\tStop 'data saved in rk4.dat'\r\n End\r\nc------------------------end of main program------------------------\r\nc\r\nc fourth-order Runge-Kutta subroutine \r\n\tSubroutine rk4(x, xstep, y, n)\r\n\tImplicit none\r\nc declarations\r\n\tReal*8 deriv, h, x, xstep, y(5) \r\n Real*8 k1(5), k2(5),k3(5), k4(5), t1(5), t2(5), t3(5)\r\n \tInteger i, n\r\n \th=xstep/2.0\r\n\tDo 10 i = 1,n\r\n\t k1(i) = xstep * deriv(x, y, i)\r\n\t t1(i) = y(i) + 0.5*k1(i)\r\n 10\tContinue\r\n\tDo 20 i = 1,n\r\n\t k2(i) = xstep * deriv(x+h, t1, i)\r\n\t t2(i) = y(i) + 0.5*k2(i)\r\n 20\tContinue\r\n\tDo 30 i = 1,n\r\n\t k3(i) = xstep * deriv(x+h, t2, i)\r\n\t t3(i) = y(i) + k3(i)\r\n 30\tContinue\r\n\tDo 40 i = 1,n\r\n\t k4(i) = xstep * deriv(x+xstep, t3, i)\r\n\t y(i) = y(i) + (k1(i) + (2.*(k2(i) + k3(i))) + k4(i))/6.0\r\n 40\tContinue\r\nc \r\n\tReturn\r\n\tEnd\r\nc function which returns the derivatives\r\n\tFunction deriv(x, temp, i)\r\n\tImplicit none\r\nc declarations\r\n\tReal*8 deriv, x, temp(2), omega, alpha\r\n\tInteger i\r\n\tdata omega /1.d0/\r\n\tdata alpha /0.5d0/\r\nc\r\n\tIf (i .EQ. 1) deriv=temp(2)\r\n\tIf (i .EQ. 2) deriv=-temp(1) * omega**2 -alpha*temp(2) \r\n\tReturn\r\n\tEnd\r\n", "meta": {"hexsha": "1c293681b2d5bc6fef0b9d4405aa65113aa3b50b", "size": 1626, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math3/rk4.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/rk4.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/rk4.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": 24.2686567164, "max_line_length": 69, "alphanum_fraction": 0.5381303813, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430803622103, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.8109896727820345}} {"text": "!> @brief This function returns the integral of the supplied 1D tabulated data.\n!>\n!> @param[in] x1 The variable of integration.\n!>\n!> @param[in] arr The integrand.\n!>\n!> @note \"x1\" does not have to be uniform.\n!>\n!> @warning \"x1\" must be the same dimension as \"arr\".\n!>\n\nPURE FUNCTION func_integrate_1D_REAL64_real_array(x1, 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) :: 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) :: n1\n\n ! Find size of input array ...\n n1 = SIZE(x1, 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 ! Integrate via the trapezium rule ...\n ans = ans + (x1(i1 + 1_INT64) - x1(i1)) * 0.5e0_REAL64 * (arr(i1) + arr(i1 + 1_INT64))\n END DO\nEND FUNCTION func_integrate_1D_REAL64_real_array\n", "meta": {"hexsha": "9b50bd7926c1bcd1f25c219428e7b22087581a5c", "size": 1307, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_integrate_array/func_integrate_1D_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_1D_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_1D_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": 32.675, "max_line_length": 94, "alphanum_fraction": 0.5233358837, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.8109617185284554}} {"text": "\n!\n! This program sets up a simple 3x3 symmetric matrix and finds its\n! determinant and inverse\n!\n\nPROGRAM matrix\n USE constants\n USE F90library\n IMPLICIT NONE\n ! The definition of the matrix, using dynamic allocation\n REAL(DP), ALLOCATABLE, DIMENSION(:,:) :: a, ainv, unity\n ! the determinant\n REAL(DP) :: d\n ! The size of the matrix\n INTEGER :: n\n ! Here we set the dim n=3\n n=3\n ! Allocate now place in heap for a\n ALLOCATE ( a(n,n), ainv(n,n), unity(n,n) )\n a(1,1)=1. ; a(1,2)=3.; a(1,3)=4. \n a(2,1)=3. ; a(2,2)=4.; a(2,3)=6. \n a(3,1)=4. ; a(3,2)=6.; a(3,3)=8. \n WRITE(6,*) ' The matrix before inversion'\n WRITE(6,'(3F12.6)') a\n ainv=a\n CALL matinv (ainv, n, d)\n WRITE(6,*) ' The determinant'\n WRITE(6,'(F12.6)') d\n WRITE(6,*) ' The matrix after inversion'\n WRITE(6,'(3F12.6)') ainv\n ! get the unity matrix\n unity=MATMUL(ainv,a)\n WRITE(6,*) ' The unity matrix'\n WRITE(6,'(3F12.6)') unity \n ! deallocate all arrays\n DEALLOCATE (a, ainv, unity)\n\nEND PROGRAM matrix\n", "meta": {"hexsha": "6e7be4a7fd9006953476adb13a454ae5041ddfc9", "size": 1043, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/LinAlgebra/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/LinAlgebra/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/LinAlgebra/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": 26.075, "max_line_length": 72, "alphanum_fraction": 0.5944391179, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693659780479, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.8109347844615138}} {"text": "! Multiples of 3 and 5\n!\n! If we list all the natural numbers below 10 that are multiples of 3 or 5,\n! we get 3, 5, 6 and 9. The sum of these multiples is 23.\n!\n! Find the sum of all the multiples of 3 or 5 below 1000.\nmodule Problem1\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 1. Multiples of 3 and 5.'\n\n write (*, '(A, I)') 'Multiply 1: ', multiply1()\n write (*, '(A, I)') 'Multiply 2: ', multiply2()\n end subroutine\n\n ! A simple way to do this is to go through all numbers from 1 to 999\n ! and test whether they are divisible by 3 or by 5.\n function multiply1()\n integer multiply1\n integer index\n\n ! initial value\n multiply1 = 0\n\n do index = 2, 999\n if ((mod(index, 3) .eq. 0) .or. (mod(index, 5) .eq. 0)) then\n multiply1 = multiply1 + index\n end if\n end do\n end function\n\n ! To get a more efficient solution you could also calculate the sum of\n ! the numbers less than 1000 that are divisible by 3, plus the sum of\n ! the numbers less than 1000 that are divisible by 5. But as you have\n ! summed numbers divisible by 15 twice you would have to subtract the\n ! sum of the numbers divisible by 15\n function multiply2()\n integer multiply2\n\n multiply2 = sumDevisibleBy(3) + sumDevisibleBy(5) - sumDevisibleBy(15)\n end function\n\n ! 3 + 6 + 9 + 12 + ...... + 999 = 3 * (1 + 2 + 3 + 4 + ... + 333)\n function sumDevisibleBy(num)\n integer sumDevisibleBy\n integer num\n integer index\n\n ! nearest integer to the argument\n index = nint(999.0 / num)\n\n sumDevisibleBy = nint(DBLE(num * (index * (index + 1))) / 2)\n end function\nend module\n", "meta": {"hexsha": "451965b55d39f47cc86d27d9364f1a01cb24db04", "size": 1796, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem1.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": "Problem1.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": "Problem1.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": 29.9333333333, "max_line_length": 79, "alphanum_fraction": 0.6041202673, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.8109287154766974}} {"text": "! Last change: 95 21 Jul 2013 11:06 pm\r\nPROGRAM PB45\r\nF(X)=X*EXP(X)\r\nDIMENSION R(100,100)\r\nOPEN(1,FILE='MP.DAT')\r\nOPEN(2,FILE='NP.DAT')\r\nREAD(1,*)XO,P,N\r\nR(1,1)=(1.0/(2*P))*(F(XO+P)-F(XO-P))\r\nR(2,1)=((1.0/P)*(F(XO+(P/2))-F(XO-(P/2))))\r\nDO J=3,N\r\nR(J,1)=(1.0/(2*(P/(2**(J-1)))))*(F(XO+(P/(2**(J-1))))-F(XO-(P/(2**(J-1)))))\r\nEND DO\r\nDO I=2,N\r\nDO J=2,I\r\nR(I,J)=R(I,J-1)+((R(I,J-1)-R(I-1,J-1))/(4**(J-1)-1))\r\nEND DO\r\nEND DO\r\nWRITE(2,*)'==============RICHARDSON EXTRAPOLATION METHOD================='\r\nWRITE(2,*)\r\nDO I=1,N\r\nWRITE(2,10)(R(I,J),J=1,I)\r\n10 FORMAT(12(2X,F10.6))\r\nEND DO\r\nWRITE(2,*)\r\nWRITE(2,*)'=============FINALLY WE GET THE VALUE OF DERIVATIVE OF F(X) AT DEFINED POINT AS======='\r\nWRITE(2,*)\r\nWRITE(2,*)R(N,N)\r\nEND\r\n", "meta": {"hexsha": "884a994da7ddba3b8b31d41fb7d6740f39c81f4a", "size": 735, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Richard.f90", "max_stars_repo_name": "FahadMostafa91/Richardson_extrapolation", "max_stars_repo_head_hexsha": "a2d584a34fd60fd996e8f6823f83713c70eaae6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Richard.f90", "max_issues_repo_name": "FahadMostafa91/Richardson_extrapolation", "max_issues_repo_head_hexsha": "a2d584a34fd60fd996e8f6823f83713c70eaae6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Richard.f90", "max_forks_repo_name": "FahadMostafa91/Richardson_extrapolation", "max_forks_repo_head_hexsha": "a2d584a34fd60fd996e8f6823f83713c70eaae6f", "max_forks_repo_licenses": ["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.3448275862, "max_line_length": 99, "alphanum_fraction": 0.4979591837, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452771, "lm_q2_score": 0.8479677660619634, "lm_q1q2_score": 0.8106413719995097}} {"text": "!!# MODULE <>\nMODULE TBX_ComputationalGeometry\n\n!!## PURPOSE\n!! The geometry toolkit defines many geometrical operations such as dot products,\n!! cross products, intersections, mappings, and distance, area , and volume calculations\n!! for various common shapes such as triangles, quadrilaterals, polygons, circles,\n!! tetrahedrons, boxes, and spheres.\n!\n!! The world is assumed to be described by cartesian x-y-z geometry, but objects in the\n!! world may be described with cartesian geometry, spherical r-p-a\n!! (radius-polar angle-azimuthal angle) geometry, or cylindrical r-h-p (radius-height-polar angle)\n!! geometry.\n\n\n!!## NOMENCLATURE\n!! This section attempts to describe the various nomenclature you will encounter\n!! in this geometry toolkit.\n\n!! * SCALARS\n!! These variable names indicate scalars with various properties.\n!! s,d : scalar real\n!! x : x-component value\n!! y : y-component value\n!! z : z-component value\n!! r : radius value\n!! rsqr : radius squared value\n!! p : polar angle value\n!! a : azimuthal angle value\n!! h : height value\n!! N : number (integer)\n!! DIST : distance\n!! AREA : area\n!! VOLU : volume\n!! sDIST : signed distance\n!! sAREA : signed area\n\n!! * ALGORITHM SPECIFICATION I: operator\n!! The following operators exist in the geometry toolkit.\n!! DOT_ : dot product of two vectors\n!! CROSS_ : cross product of two vectors\n!! NORM_ : normalization of two vectors\n!! AREA_ : area calculation for a surface\n!! sAREA_ : signed area calculation for a surface\n!! DIST_ : distance calculation\n!! sDIST_ : signed distance calculation\n!! VOLU_ : volume calculation\n!! CENTROID_ : centroid calculation\n!! INTERSECT_ : intersection calculation\n\n!!## EXTERNAL PARAMETERS\nUSE PAR_ComputationalGeometry !!((02-A-PAR_ComputationalGeometry.f90))\n\n!!## BASIC ROUTINES\n!! * number of dimensions for rectangular geometry variables in 1D, 2D, and 3D.\nUSE FUN_NDIM !!((08-B-FUN_NDIM.f90))\n\n!!### 2-d calculational routines\nUSE FUN_xyANGLE !!((05-B-FUN_xyANGLE.f90))\nUSE FUN_xyCENTROID !!((05-B-FUN_xyCENTROID.f90))\nUSE FUN_xyCOLINEAR !!((05-B-FUN_xyCOLINEAR.f90))\nUSE FUN_xyCONTIGUOUS !!((06-B-FUN_xyCONTIGUOUS.f90))\nUSE FUN_xyCONVEXHULL !!((07-B-FUN_xyCONVEXHULL.f90))\nUSE FUN_xyCOPLANAR !!((06-B-FUN_xyCOPLANAR.f90))\nUSE FUN_xyDIRECTION !!((04-B-FUN_xyDIRECTION.f90))\nUSE FUN_xyDIST !!((04-B-FUN_xyDIST.f90))\nUSE FUN_rpDOT !!((03-A-FUN_rpDOT.f90))\nUSE FUN_xyDOT !!((03-A-FUN_xyDOT.f90))\nUSE FUN_xyINTERIOR !!((07-B-FUN_xyINTERIOR.f90))\nUSE FUN_xyINTERSECT !!((06-A-FUN_xyINTERSECT.f90))\nUSE FUN_xyLINE !!((05-B-FUN_xyLINE.f90))\nUSE FUN_xyLINESEGMENT !!((05-B-FUN_xyLINESEGMENT.f90))\nUSE FUN_xyNORM !!((03-A-FUN_xyNORM.f90))\nUSE FUN_xyPERPCW !!((04-A-FUN_xyPERPCW.f90))\nUSE FUN_xyPERPCCW !!((03-A-FUN_xyPERPCCW.f90))\nUSE FUN_xyPLANE !!((05-B-FUN_xyPLANE.f90))\nUSE FUN_xyPOINT !!((05-B-FUN_xyPOINT.f90))\nUSE FUN_xyPOLYGON !!((08-A-FUN_xyPOLYGON.f90))\nUSE FUN_xyQUADRILATERAL !!((08-A-FUN_xyQUADRILATERAL.f90))\nUSE FUN_xyRAY !!((05-B-FUN_xyRAY.f90))\nUSE FUN_xyREFLECT !!((05-B-FUN_xyREFLECT.f90))\nUSE FUN_xyROTATE !!((05-B-FUN_xyROTATE.f90))\nUSE FUN_xySAREA !!((03-A-FUN_xySAREA.f90))\nUSE FUN_xySDIST !!((03-A-FUN_xySDIST.f90))\nUSE FUN_xyTRIANGULATE !!((07-B-FUN_xyTRIANGULATE.f90))\nUSE FUN_xyUNITVECTOR !!((04-A-FUN_xyUNITVECTOR.f90))\nUSE FUN_xyVECTOR !!((03-A-FUN_xyVECTOR.f90))\nUSE FUN_xyINTEGRAL1 !!((06-A-FUN_xyINTEGRAL1.f90))\nUSE FUN_xyINTEGRALX !!((07-A-FUN_xyINTEGRALX.f90))\nUSE FUN_xyINTEGRALY !!((07-A-FUN_xyINTEGRALY.f90))\nUSE FUN_xyINTEGRALF !!((08-A-FUN_xyINTEGRALF.f90))\nUSE FUN_xyNORMSQRD !!((03-A-FUN_xyNORMSQRD.f90))\nUSE FUN_xyINTEGRALF !!((08-A-FUN_xyINTEGRALF.f90))\n\n!!### 3-d calculational routines\nUSE FUN_xyzSAREA !!((06-B-FUN_xyzSAREA.f90))\nUSE FUN_xyzPLANE !!((06-B-FUN_xyzPLANE.f90))\nUSE FUN_xyzINTERSECT !!((07-B-FUN_xyzINTERSECT.f90))\nUSE FUN_xyzDOT !!((05-B-FUN_xyzDOT.f90))\nUSE FUN_xyzCROSS !!((05-B-FUN_xyzCROSS.f90))\nUSE FUN_xyzCENTROID !!((07-B-FUN_xyzCENTROID.f90))\nUSE FUN_xyzPLANE !!((06-B-FUN_xyzPLANE.f90))\nUSE FUN_xyzCOPLANAR !!((07-B-FUN_xyzCOPLANAR.f90))\nUSE FUN_xyzSDIST !!((06-B-FUN_xyzSDIST.f90))\n\n!!### allocation routines\nUSE LIB_ALLOCATE_Shape !!((03-A-LIB_ALLOCATE_Shape.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## DEFAULT ACCESS\nPUBLIC\n\nEND MODULE\n", "meta": {"hexsha": "03fbad0c5986d6e7896147230865765c5a6a09af", "size": 4915, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/09-A-TBX_ComputationalGeometry.f90", "max_stars_repo_name": "wawiesel/tapack", "max_stars_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/09-A-TBX_ComputationalGeometry.f90", "max_issues_repo_name": "wawiesel/tapack", "max_issues_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": "src/09-A-TBX_ComputationalGeometry.f90", "max_forks_repo_name": "wawiesel/tapack", "max_forks_repo_head_hexsha": "ac3e492bc7203a0e4167b37ba0278daa5d40d6ef", "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": 42.3706896552, "max_line_length": 98, "alphanum_fraction": 0.6400813835, "num_tokens": 1424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025386, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.8104440832384907}} {"text": "PROGRAM testingInt\n IMPLICIT NONE\n\n REAL(4) :: shortval\n REAL(8) :: longval\n REAL :: defval\n INTEGER :: i\n !===============================================================!\n ! print out 2**127 always get the error \"Arithematica overflow !\n ! I know in Fortran the LHS is evaluated before assigning to the!\n ! RHS. so `real(kind=8) :: var = 2d0**127d0`is invalid !\n !===============================================================!\n\n INTEGER, PARAMETER :: dp1 = KIND(1.)\n INTEGER, PARAMETER :: dp2 = KIND(0.0d0)\n REAL(kind = 4) :: mantissa1\n REAL(kind = 8) :: mantissa2\n\n mantissa1 = 0d0\n mantissa2 = 0d0\n\n DO i = 0, 23\n mantissa1 = mantissa1 + 1./(2 ** i)\n END DO\n\n\n DO i = 0, 52\n mantissa2 = mantissa2 + 1d0/(2d0 ** i)\n END DO\n\n WRITE (*,*) 2d2,2e2, 2d2-2e2\n WRITE(*,*)\"------------------------------------------------------------------------------\"\n PRINT *,\"KIND(1.)=\",KIND(1.)\n PRINT *,\"kind(1d0)= \",KIND(1d0)\n PRINT *,\"kind of real = \",KIND(defval)\n WRITE(*,*)\"------------------------------------------------------------------------------\"\n WRITE(*,*)\"Ranges of floating point datatypei with kind = 4 in Fortran\"\n PRINT *,\"The lagest number : mantissa1 * 2d0 ** 127_dp1 = \",mantissa1 * 2d0 ** 127.\n PRINT *,\"The smallest numer: mantissa1 * 2d0 ** 127_dp1 = \",mantissa1 * 2d0 ** (-127.)\n\n WRITE(*,*)\"------------------------------------------------------------------------------\"\n WRITE(*,*)\"Ranges of floating point datatypei with kind = 8 in Fortran\"\n PRINT *,\"The lagest number : mantissa2 * 2d0 ** 1023_dp2 = \",mantissa2 * 2d0 ** 1023_dp2\n PRINT *,\"The smallest numer: mantissa2 * 2d0 ** 1023_dp2 = \",mantissa2 * 2d0 ** (-1023_dp2)\n\n WRITE(*,*)\"------------------------------------------------------------------------------\"\n WRITE(*,*)\"Fetch the parameters by intrinsic functions\"\n PRINT *,\"The largest number of real with kind=4 is :\",HUGE(shortval)\n PRINT *,\"The tinest number of real with kind=4 is : \",TINY(shortval)\n PRINT *,\"The largest number of real with kind=8 is :\",HUGE(longval)\n PRINT *,\"The tinest number of real with kind=8 is :\",TINY(longval)\n PRINT *,\"The largest number of real with default kind is :\",HUGE(defval)\n WRITE(*,*)\"------------------------------------------------------------------------------\"\nEND PROGRAM testingInt\n", "meta": {"hexsha": "89a1058f5924f966966999a6da2585734536e54c", "size": 2320, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/data_type/data_type.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/data_type/data_type.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/data_type/data_type.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": 42.1818181818, "max_line_length": 93, "alphanum_fraction": 0.4892241379, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.8102650804285935}} {"text": "! From Advance Fortran Programming\n! https://www.youtube.com/watch?v=Ey7mX94Cy_E&list=PLNmACol6lYY4wPUNCK03LOwVTBbca7Ix- \n\n! Program for demonstrating array operations\nprogram array_funcs\n use maths1\n implicit none\n real*8::prod,sum1\n integer, parameter:: r=3,c=2\n real*8, dimension(1) :: dp\n real*8, dimension(r,c) :: a1\n real*8, dimension(r,r) :: a3\n real*8, dimension(c,r) :: at, a2\n real*8, dimension(r*c) :: b1, b2 \n\n a1 = reshape((/1,2,3,4,5,6/),(/r,c/))\n a2 = reshape((/1,2,3,4,5,6/),(/c,r/))\n b1 = reshape((/1,2,3,4,5,6/),(/r*c/))\n b2 = reshape((/1,2,3,4,5,6/),(/r*c/))\n\n dp = dot_product(b1,b2)\n at = transpose(a1)\n a3 = matmul(a1,a2) \n prod = product(a1)\n sum1 = sum(a1) \n\n print *, \"The matrix a1 is: \"\n call print_mat2(a1,r,c)\n\n print *, \"The matrix a2 is: \"\n call print_mat2(a2,c,r)\n\n print *, \"Max value of a1 is: \", maxval(a1)\n print *, \"Min value of a1 is: \", minval(a1)\n print *, \"The sum of a1 is: \", sum1\n print *, \"The prod of a1 is: \", prod\n\n print *, \"The transpose of a1 is: \"\n call print_mat2(at,c,r)\n\n print *, \"The Matrix Multiplication of a1 and a2 is:\"\n call print_mat2(a3,r,r)\n\n \n print *,SHAPE(a1) ! (/ 3, 4 /)\n print *,SIZE(SHAPE(42)) ! (/ /)\nend program array_funcs", "meta": {"hexsha": "b921221dad3ecbffcd303ed57d48d1b0a1e7d857", "size": 1313, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran-openacc/Array_Functions/main.f95", "max_stars_repo_name": "aandrich3/fortran", "max_stars_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_stars_repo_licenses": ["MIT"], "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-openacc/Array_Functions/main.f95", "max_issues_repo_name": "aandrich3/fortran", "max_issues_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-11T20:42:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-11T20:42:37.000Z", "max_forks_repo_path": "fortran-openacc/Array_Functions/main.f95", "max_forks_repo_name": "aandrich3/fortran", "max_forks_repo_head_hexsha": "ed98e52679bee764b5ad9a1a0545a17d8ded3066", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-11T17:22:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-06T14:41:36.000Z", "avg_line_length": 27.9361702128, "max_line_length": 86, "alphanum_fraction": 0.5742574257, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8102388597446248}} {"text": "!5. Modify the previous program such that only multiples of three or five are considered in the sum, e.g. 3, 5, 6, 9, 10, 12, 15 for n=17\n \n program Exercises\n implicit none\n integer :: n\n integer :: sum\n integer :: i\n \n print *, 'Please enter a number, n:'\n read *, n\n \n sum = 0\n do i=1,n\n ! Could use modulo or mod-- modulo is 95 standard, mod is 77 standard. \n ! They give different results for negative numbers. These numbers are positive so it doesn't matter.\n if (mod(i, 3) .eq. 0 .or. mod(i, 5) .eq. 0) then\n sum = sum + i\n end if\n end do\n \n print '(A, I0)', 'The sum of the multiples-of-3 and multiples-of-5 from 1 to n is: ', sum\n \n end program Exercises", "meta": {"hexsha": "1c229d1a69cfd935b6333a660db5f3c5d39dac6c", "size": 753, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "E05.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": "E05.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": "E05.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": 32.7391304348, "max_line_length": 137, "alphanum_fraction": 0.5869853918, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132747, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.810145843264429}} {"text": "SUBROUTINE trapzd(a,b,s,n)\n!\n! this routine is an algorithm which performs integration on a\n! function. the algorithm is based on the extended trapzoidal rule.\n! the routine integrates the function between a and b. n represents\n! the n'th stage of refinment of the trapzoid rule. n=1 gives the\n! crudest estimate of the integrated function, subsequent call with\n! n=2,3,... improve the accuracy of the calculation. s is the value\n! of the integral and should not be modified between sequential calls.\n! for more info refer to \"numerical recipies-the art of scientific computing\"\n! cambridge university press, 1986.\n!\nIMPLICIT NONE\n!\n! Subroutine arguments\n!\nREAL :: a,b,s\nINTEGER :: n\n!\n! Local variables\n!\nREAL :: del,sum,x\nREAL :: func\nINTEGER :: it,j,tmn\n!\nIF (n.EQ.1) THEN\n s = 0.5*(b-a)*(func(a)+func(b))\n it = 1\nELSE\n tmn = it\n del = (b-a)/tmn\n x = a + 0.5*del\n sum = 0.0\n DO j = 1,it\n sum = sum + func(x)\n x = x + del\n END DO\n s = 0.5*(s+(b-a)*sum/tmn)\n it = 2*it\nEND IF\n!\nEND SUBROUTINE trapzd\n", "meta": {"hexsha": "47b698a233625f7740c38a3ac51399ab6066c1e7", "size": 1033, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Trapzd.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/Trapzd.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/Trapzd.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": 24.023255814, "max_line_length": 78, "alphanum_fraction": 0.6737657309, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.8099684017026796}} {"text": "program rootsOfQuadraticEquation\n implicit none;\n Real F, x, a, b, c;\n Real D, R1, R2;\n F(x) = a * (x**2) + b * x + c;\n\n write(*, *)\"Enter Value of A, B & C...\";\n read *, a, b, c;\n \n print *, \"A : \", a;\n print *, \"B : \", b;\n print *, \"C : \", c;\n\n D = b**2 - 4 * a * c;\n print *, \"D : \", D;\n\n print *, \"\";\n if(D .ge. 0) then ! Real roots\n R1 = (-b + sqrt(D)) / 2 * a;\n R2 = (-b - sqrt(D)) / 2 * a;\n print *, \"R1 : \", R1;\n print *, \"R2 : \", R2;\n else ! Complex Roots\n print *, \"There is no real roots, D = \", D;\n end if;\n\nend program rootsOfQuadraticEquation", "meta": {"hexsha": "03958f97ec2e0c1f1b6ac7c44cb68997b9322886", "size": 659, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/rootsOfQuadraticEquation.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/rootsOfQuadraticEquation.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/rootsOfQuadraticEquation.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": 24.4074074074, "max_line_length": 51, "alphanum_fraction": 0.4127465857, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620539235895, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.8099385006918735}} {"text": "SUBROUTINE pd_gm (GM, r, U )\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: pd_gm\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Partial derivatives of the acceleration due to the central Earth Gravity\r\n! field (based on Newton's law of gravity 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! - U: \t\t\t\tMatrix of the partial derivatives of the acceleration\r\n! \t\t\t\tgiven in the form of second partial derivatives of \r\n!\t\t\t\t\tgeopotential Uxx, Uyy, Uzz, Uxy, Uxz, Uyz \r\n! ----------------------------------------------------------------------\r\n! Note:\r\n! Matrix of second partial derivatives:\r\n! U = [ Uxx Uxy Uxz \r\n! Uxy Uyy Uyz\r\n! Uxz Uyz Uzz ] \r\n! \r\n! Partial derivatives are noted as:\r\n! dfx / dy = Uxy, dfx / dx = Uxx\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\t11 December 2017\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) :: U(3,3)\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) :: x, y, z\r\n REAL (KIND = prec_q) :: Uxx, Uyy, Uzz, Uxy, Uxz, Uyz \r\n REAL (KIND = prec_q) :: Uo(3,3) \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! computation of spherical coordinates\r\n CALL coord_r2sph (r , phi,lamda,radius)\r\n\t \r\n! r coordinates x,y,z\r\nx = r(1)\r\ny = r(2)\r\nz = r(3)\r\n\r\n! Computation of second partial derivatives Uxx, Uyy, Uzz, Uxy, Uxz, Uyz\r\nUxx = 0.D0\r\nUyy = 0.D0\r\nUzz = 0.D0\r\nUxy = 0.D0\r\nUxz = 0.D0\r\nUyz = 0.D0\r\n\r\nUxx = 3 * x**2 - radius**2\r\nUyy = 3 * y**2 - radius**2\r\nUzz = 3 * z**2 - radius**2\r\nUxy = 3 * x * y\r\nUxz = 3 * x * z\r\nUyz = 3 * y * z\r\n\r\n\r\n! Matrix of second partial derivatives of geopotential V:\r\nUo(1,1:3) = (/ Uxx, Uxy, Uxz /) \r\nUo(2,1:3) = (/ Uxy, Uyy, Uyz /) \r\nUo(3,1:3) = (/ Uxz, Uyz, Uzz /) \r\n\r\nU = ( GM / radius**5 ) * Uo \t \r\n\r\n\r\n\r\nEND\r\n\r\n", "meta": {"hexsha": "39c764723225068bf8ba1d8f0826cb0693712741", "size": 2859, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/pd_gm.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/pd_gm.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/pd_gm.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.4175824176, "max_line_length": 99, "alphanum_fraction": 0.3973417279, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075733703925, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.8099268287691839}} {"text": "program compute_pi\n use, intrinsic :: iso_fortran_env, only : DP => REAL64, I8 => INT64\n implicit none\n integer(kind=I8) :: i, nr_iters\n real(kind=DP) :: delta, x, pi_val\n\n pi_val = 0.0_DP\n nr_iters = get_nr_iters()\n delta = 1.0_DP/nr_iters\n x = 0.0_DP\n do i = 1, nr_iters\n pi_val = pi_val + sqrt(1.0_DP - x**2)\n x = x + delta\n end do\n pi_val = 4.0_DP*pi_val/nr_iters\n print '(F25.15)', pi_val\n\ncontains\n \n function get_nr_iters() result(nr_iters)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n integer(kind=I8) :: nr_iters\n integer(kind=I8), parameter :: default_nr_iters = 1000_I8\n character(len=1024) :: buffer, msg\n integer :: istat\n\n if (command_argument_count() >= 1) then\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iostat=istat, iomsg=msg) nr_iters\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') &\n 'error: ', msg\n stop 1\n end if\n else\n nr_iters = default_nr_iters\n end if\n end function get_nr_iters\n\nend program compute_pi\n", "meta": {"hexsha": "75e465a4b796174b8bdcfa7cc8176e9d09f82604", "size": 1210, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/computing_pi/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/computing_pi/compute_pi.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/computing_pi/compute_pi.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": 28.8095238095, "max_line_length": 71, "alphanum_fraction": 0.5702479339, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8723473647220787, "lm_q1q2_score": 0.8098949670933726}} {"text": "program main\n \n use numeric_kinds, only: dp\n use davidson, only: generalized_eigensolver\n use array_utils, only: diagonal, norm, generate_diagonal_dominant\n\n implicit none\n\n integer, parameter :: dim = 50\n integer, parameter :: lowest = 3\n real(dp), dimension(3) :: eigenvalues_DPR, eigenvalues_GJD\n real(dp), dimension(dim, 3) :: eigenvectors_DPR, eigenvectors_GJD\n real(dp), dimension(dim, dim) :: mtx\n real(dp), dimension(dim) :: xs, ys, zs\n real(dp) :: test_norm_eigenvalues\n integer :: iter_i, j\n\n ! mtx = read_matrix(\"tests/matrix.txt\", 100)\n mtx = generate_diagonal_dominant(dim, 1d-3)\n\n call generalized_eigensolver(mtx, eigenvalues_GJD, eigenvectors_GJD, lowest, \"GJD\", 1000, 1d-8, iter_i)\n call generalized_eigensolver(mtx, eigenvalues_DPR, eigenvectors_DPR, lowest, \"DPR\", 1000, 1d-8, iter_i)\n\n print *, \"Test 1\"\n test_norm_eigenvalues = norm(eigenvalues_GJD - eigenvalues_DPR)\n print *, \"Check that eigenvalues norm computed by different methods are the same: \", test_norm_eigenvalues < 1e-8\n \n print *, \"Test 2\"\n print *, \"Check that eigenvalue equation: H V = l V holds\"\n print *, \"DPR method:\"\n do j=1,lowest\n xs = matmul(mtx, eigenvectors_DPR(:, j)) - (eigenvalues_DPR(j) * eigenvectors_DPR(:, j))\n print *, \"eigenvalue \", j, \": \", norm(xs) < 1d-8\n end do\n print *, \"GJD method:\"\n do j=1,lowest\n xs = matmul(mtx, eigenvectors_GJD(:, j)) - (eigenvalues_GJD(j) * eigenvectors_GJD(:, j))\n print *, \"eigenvalue \", j, \": \", norm(xs) < 1d-8\n end do\n\n print *, \"Test 3\"\n print *, \"If V are the eigenvector then V * V^T = I\"\n ys = diagonal(matmul(eigenvectors_GJD, transpose(eigenvectors_GJD)))\n zs = diagonal(matmul(eigenvectors_DPR, transpose(eigenvectors_DPR)))\n ! There are only 3 eigenvectors\n print *, \"GJD method: \", norm(xs(:3)) < sqrt(real(lowest))\n print *, \"DPR method: \", norm(ys(:3)) < sqrt(real(lowest))\n \n\nend program main\n", "meta": {"hexsha": "236159d0f60769de21647d4bef7b39f2ba19e3f4", "size": 1900, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_dense_properties.f90", "max_stars_repo_name": "NLESC-JCER/Fortran_Davidson", "max_stars_repo_head_hexsha": "b359691db175d450333e51d79d12cdbd367fc987", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-02-15T13:38:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T12:26:40.000Z", "max_issues_repo_path": "src/tests/test_dense_properties.f90", "max_issues_repo_name": "NLESC-JCER/Fortran_Davidson", "max_issues_repo_head_hexsha": "b359691db175d450333e51d79d12cdbd367fc987", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2019-01-14T17:03:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-13T07:56:35.000Z", "max_forks_repo_path": "src/tests/test_dense_properties.f90", "max_forks_repo_name": "NLESC-JCER/Fortran_Davidson", "max_forks_repo_head_hexsha": "b359691db175d450333e51d79d12cdbd367fc987", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-30T22:56:01.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-21T11:55:19.000Z", "avg_line_length": 37.2549019608, "max_line_length": 115, "alphanum_fraction": 0.6852631579, "num_tokens": 629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.8097712711124265}} {"text": " !>@author\n !>Paul Connolly, The University of Manchester\n !>@brief\n !>code to solve a tridiagonal system of equations based \n !> based on the Thomas algorithm: \n !> https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm\n !> https://en.wikibooks.org/wiki/Algorithm_Implementation/Linear_Algebra/Tridiagonal_matrix_algorithm\n !>@param[in] a,b,c,r\n !>@param[inout] x - solution vector\n subroutine tridiagonal(a,b,c,r,x)\n use numerics_type\n use numerics, only : assert_eq, numerics_error\n implicit none\n real(wp), dimension(:), intent(in) :: a,b,c,r\n real(wp), dimension(:), intent(inout) :: x\n real(wp), dimension(size(b)) :: cp\n real(wp) :: m\n integer(i4b) :: n,i\n \n n=assert_eq((/size(a)+1,size(b),size(c)+1,size(r),size(x)/),'tridiagonal')\n m=b(1)\n if (m == 0.0_wp) call numerics_error('tridiagonal: Error first divide')\n x(1)=r(1)/m\n\n ! forward sweep\n do i = 2,n\n cp(i)=c(i-1)/m\n m = b(i)-cp(i)*a(i-1)\n if (m == 0.0_wp) call numerics_error('tridiagonal: Error 2nd divide')\n x(i) = (r(i)-x(i-1)*a(i-1))/m\n enddo\n ! backsubstitution\n do i = n-1, 1, -1\n x(i) = x(i)-cp(i+1)*x(i+1)\n end do \n end subroutine tridiagonal\n", "meta": {"hexsha": "4b34c0506547d1c1ec4d7ab9675eccdf1b7eecf5", "size": 1347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tridiagonal.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": "tridiagonal.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": "tridiagonal.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": 36.4054054054, "max_line_length": 105, "alphanum_fraction": 0.5590200445, "num_tokens": 413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.8097712648707692}} {"text": "MODULE interpolation\r\n\r\nCONTAINS\r\n SUBROUTINE interp1( x, y, xi, yi )\r\n\r\n ! Given a set of points (x, y), computes the interpolated value at xi\r\n ! using piecewise linear interpolation\r\n\r\n ! Assumes x is monotonically increasing\r\n\r\n IMPLICIT NONE\r\n REAL (KIND=8), INTENT( IN ) :: x( : ), y( : ), xi( : )\r\n REAL (KIND=8), INTENT( OUT ) :: yi( : )\r\n INTEGER :: N, Ni, I, iseg\r\n REAL (KIND=8) :: R\r\n\r\n N = SIZE( x )\r\n Ni = SIZE( xi )\r\n iseg = 1\r\n\r\n ! loop over the interpolation points\r\n DO I = 1, Ni\r\n ! search for the bracketting pair of tabulated values\r\n DO WHILE ( xi( I ) > x( iseg + 1 ) ) ! is the xi point to the right of the current segment?\r\n IF ( iseg < N - 2 ) THEN\r\n iseg = iseg + 1\r\n END IF\r\n END DO\r\n\r\n DO WHILE ( xi( I ) < x( iseg ) ) ! is the xi point to the left of the current segment?\r\n IF ( iseg > 1 ) THEN\r\n iseg = iseg - 1\r\n END IF\r\n END DO\r\n\r\n ! proportional distance between points\r\n R = ( xi( I ) - x( iseg ) ) / ( x( iseg + 1 ) - x( iseg ) )\r\n yi( I ) = ( 1.0 - R ) * y( iseg ) + R * y( iseg + 1 )\r\n END DO\r\n\r\n END SUBROUTINE interp1\r\nEND MODULE interpolation\r\n", "meta": {"hexsha": "ca297567f122d191a0e4c98d1f8d1ca71d73b794", "size": 1293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/misc/interpolation.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/interpolation.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/at/misc/interpolation.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": 30.0697674419, "max_line_length": 100, "alphanum_fraction": 0.4911059551, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133430934989, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.809771261970619}} {"text": "module statistics_module\n\n contains\n subroutine stats(x, n, mean, std_dev, median)\n implicit none\n\n integer, intent(in) :: n\n real, dimension(:), intent(in) :: x\n real, intent(out) :: mean, std_dev, median\n real, dimension (1:n) :: y\n real :: variance\n real :: sumxi, sumxi2\n\n sumxi = sum(x)\n sumxi2 = sum(x*x)\n mean = sumxi/n\n variance = (sumxi2-sumxi*sumxi/n)/(n-1)\n std_dev = sqrt(variance)\n y = x\n if (mod(n,2)==0) then\n median = (find(n/2)+find(n/2+1))/2\n else\n median = find(n/2+1)\n end if\n\n contains\n real function find(k)\n implicit none\n\n integer, intent(in) :: k\n integer :: lt, rt, i, j\n real :: t1, t2\n\n lt = 1\n rt = n\n do while (ltj) exit\n end do\n if (j exp_lambda) \n\t\t randUni = funUniformSingle() !generate uniform variable\n\t\t prodUni = prodUni * randUni !update product\n\t\t randPoisson = randPoisson + 1 !increase Poisson variable\n\tend do \nend function\n!END Function definitions", "meta": {"hexsha": "1eabe5567c41e629563ac3a51ec2556131f335b3", "size": 2732, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "PoissonDirectFortran/PoissonDirectSingle.f95", "max_stars_repo_name": "hpkeeler/posts", "max_stars_repo_head_hexsha": "a45c951bcccca3061276b2576e2568560f4bffdd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2020-05-14T12:14:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T15:22:09.000Z", "max_issues_repo_path": "PoissonDirectFortran/PoissonDirectSingle.f95", "max_issues_repo_name": "hpkeeler/posts", "max_issues_repo_head_hexsha": "a45c951bcccca3061276b2576e2568560f4bffdd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PoissonDirectFortran/PoissonDirectSingle.f95", "max_forks_repo_name": "hpkeeler/posts", "max_forks_repo_head_hexsha": "a45c951bcccca3061276b2576e2568560f4bffdd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2019-10-26T01:22:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T17:33:40.000Z", "avg_line_length": 30.3555555556, "max_line_length": 131, "alphanum_fraction": 0.7287701318, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.8094534199701245}} {"text": "! { dg-do run }\n!\n! PR fortran/33197\n!\n! Check implementation of L2 norm (Euclidean vector norm)\n!\nimplicit none\n\nreal :: a(3) = [real :: 1, 2, huge(3.0)]\nreal :: b(3) = [real :: 1, 2, 3]\nreal :: c(4) = [real :: 1, 2, 3, -1]\nreal :: e(0) = [real :: ]\nreal :: f(4) = [real :: 0, 0, 3, 0 ]\n\nreal :: d(4,1) = RESHAPE ([real :: 1, 2, 3, -1], [4,1])\nreal :: g(4,1) = RESHAPE ([real :: 0, 0, 4, -1], [4,1])\n\n! Check compile-time version\n\nif (abs (NORM2 ([real :: 1, 2, huge(3.0)]) - huge(3.0)) &\n > epsilon(0.0)*huge(3.0)) STOP 1\n\nif (abs (SNORM2([real :: 1, 2, huge(3.0)],3) - huge(3.0)) &\n > epsilon(0.0)*huge(3.0)) STOP 2\n\nif (abs (SNORM2([real :: 1, 2, 3],3) - NORM2([real :: 1, 2, 3])) &\n > epsilon(0.0)*SNORM2([real :: 1, 2, 3],3)) STOP 3\n\nif (NORM2([real :: ]) /= 0.0) STOP 4\nif (abs (NORM2([real :: 0, 0, 3, 0]) - 3.0) > epsilon(0.0)) STOP 5\n\n! Check TREE version\n\nif (abs (NORM2 (a) - huge(3.0)) &\n > epsilon(0.0)*huge(3.0)) STOP 6\n\nif (abs (SNORM2(b,3) - NORM2(b)) &\n > epsilon(0.0)*SNORM2(b,3)) STOP 7\n\nif (abs (SNORM2(c,4) - NORM2(c)) &\n > epsilon(0.0)*SNORM2(c,4)) STOP 8\n\nif (ANY (abs (abs(d(:,1)) - NORM2(d, 2)) &\n > epsilon(0.0))) STOP 9\n\n! Check libgfortran version\n\nif (ANY (abs (SNORM2(d,4) - NORM2(d, 1)) &\n > epsilon(0.0)*SNORM2(d,4))) STOP 10\n\nif (abs (SNORM2(f,4) - NORM2(f, 1)) &\n > epsilon(0.0)*SNORM2(d,4)) STOP 11\n\nif (ANY (abs (abs(g(:,1)) - NORM2(g, 2)) &\n > epsilon(0.0))) STOP 12\n\ncontains\n ! NORM2 algorithm based on BLAS, cf.\n ! http://www.netlib.org/blas/snrm2.f\n REAL FUNCTION SNORM2 (X,n)\n INTEGER, INTENT(IN) :: n\n REAL, INTENT(IN) :: X(n)\n\n REAL :: absXi, scale, SSQ\n INTEGER :: i\n\n INTRINSIC :: ABS, SQRT\n\n IF (N < 1) THEN\n snorm2 = 0.0\n ELSE IF (N == 1) THEN\n snorm2 = ABS(X(1))\n ELSE\n scale = 0.0\n SSQ = 1.0\n\n DO i = 1, N\n IF (X(i) /= 0.0) THEN\n absXi = ABS(X(i))\n IF (scale < absXi) THEN\n SSQ = 1.0 + SSQ * (scale/absXi)**2\n scale = absXi\n ELSE\n SSQ = SSQ + (absXi/scale)**2\n END IF\n END IF\n END DO\n snorm2 = scale * SQRT(SSQ)\n END IF\n END FUNCTION SNORM2\nend\n", "meta": {"hexsha": "db8cb52f4d5e5a1fac6281cbe5653047f01857c4", "size": 2299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/norm2_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/norm2_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/norm2_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": 24.9891304348, "max_line_length": 66, "alphanum_fraction": 0.4784688995, "num_tokens": 966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8757869884059266, "lm_q1q2_score": 0.8093513850386492}} {"text": "module m_call_back\n use iso_c_binding , only : c_double, c_int64_t, c_char, c_size_t\n implicit none\n private\n public :: trapz, implicite, f, g\n\ncontains\n\n pure function implicite(t) result(x)\n real(c_double), intent(in) :: t\n real(c_double) :: x, F\n x = 0_c_double\n F = 4.d0 * sin( x ) - exp( x ) + t\n do \n if (abs( F ) <= 1.d-15) exit\n x = x - F/(4.d0*cos( x ) - exp( x ))\n F = 4.d0 * sin( x ) - exp( x ) + t\n end do\n end function implicite\n\n pure function trapz(a, b, n, f) result(sum_f)\n implicit none\n real(c_double), intent(in) :: a, b\n integer, intent(in) :: n\n interface\n real(c_double) pure function f(x)\n import :: c_double\n real(c_double), intent(in) :: x\n end function f\n end interface\n real(c_double) :: sum_f, h\n integer :: i\n h = (b - a) / n\n sum_f = 0.5d0 * (f( a ) + f( b ))\n do concurrent (i=1:n-1)\n sum_f = sum_f + f( i * h)\n end do \n sum_f = sum_f * h\n end function trapz\n\n pure function f(x) result(y)\n real(c_double), intent(in) :: x\n real(c_double) :: y\n y = exp(-x)*x*x\n end function f\n\n pure function g(x) result (y)\n real(c_double), intent(in) :: x\n real(c_double) :: y, h\n h = 0.d0\n if (x < 0.5d0) then\n h = -exp( -x )\n else\n h = exp( x )\n end if\n y = h * x**2\n end function g\n\nend module m_call_back\n", "meta": {"hexsha": "77b949f993a2edf2f011f6651ce8218ac980eca3", "size": 1362, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CallBack/Fortran/m_call_back.f90", "max_stars_repo_name": "aitzkora/BenchmarksPythonJuliaAndCo", "max_stars_repo_head_hexsha": "c3986d69d177e23d9a816bd5844451d9694e0638", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CallBack/Fortran/m_call_back.f90", "max_issues_repo_name": "aitzkora/BenchmarksPythonJuliaAndCo", "max_issues_repo_head_hexsha": "c3986d69d177e23d9a816bd5844451d9694e0638", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CallBack/Fortran/m_call_back.f90", "max_forks_repo_name": "aitzkora/BenchmarksPythonJuliaAndCo", "max_forks_repo_head_hexsha": "c3986d69d177e23d9a816bd5844451d9694e0638", "max_forks_repo_licenses": ["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.7, "max_line_length": 66, "alphanum_fraction": 0.5528634361, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.8093513788860299}} {"text": "! Created by EverLookNeverSee@Guthub on 06/18/20\n! I could not have done it without @ivan-pi\n\n\nmodule continued_fractions\n implicit none\n private ! makes this module private\n ! makes these entities accessible from outside of the module\n public cf, pi_seq\n ! Simple continued fraction expansion of Pi taken from https://oeis.org/A001203\n integer, parameter :: pi_seq(20) = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, &\n 14, 2, 1, 1, 2, 2, 2, 2]\n contains\n recursive function cf(b) result(pq)\n ! Returns the *simple* continued fraction of the sequence b\n ! declaring dummy parameters and local variables\n integer, intent(in) :: b(:)\n real :: pq(2)\n real :: pq_n1(2), pq_n2(2)\n integer :: n\n n = size(b)\n ! conditions to satisfy `Euler-Wallis` recurrence relations\n if (n > 2) then\n pq_n2 = cf(b(1:n-2))\n pq_n1 = cf(b(1:n-1))\n pq = b(n)*pq_n1 + pq_n2\n else if (n == 2) then\n pq_n1 = cf(b(1:1))\n pq(1) = b(2)*pq_n1(1) + 1.0\n pq(2) = b(2)\n else if (n == 1) then\n pq(1) = b(1)\n pq(2) = 1.0\n end if\n end function cf\nend module continued_fractions\n\n\nprogram main\n use continued_fractions, only: cf, pi_seq\n implicit none ! disabling implicit type assignment feature\n ! declaring and initializing variables and constants\n real :: result, pq(2)\n real, parameter :: PI = 4.0 * atan(1.0)\n ! calling function and calculating continued fraction\n pq = cf(pi_seq)\n result = pq(1) / pq(2)\n ! printing results\n print *, \"Continued fraction result:\", result\n print *, \"PI exact value:\", PI\nend program main\n", "meta": {"hexsha": "e08949d03b6b6522af089ec5d23d5862d5190168", "size": 1850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_15.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_15.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_15.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": 35.5769230769, "max_line_length": 83, "alphanum_fraction": 0.5497297297, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8093179020848312}} {"text": "program triangle\n! Takes in coordinates of a triangle and outputs if that is a scalene tr, equilaterla tr\n! or isoceles, also checks for right angled triangle.\n\n\n\n\n implicit none\n real,dimension(2) :: p1,p2,p3 !points to read\n real :: d1,d2,d3, dist !distances from each\n print *, \"Give points [2D], give x and y one after the other for each point\"\n read *, p1,p2,p3\n d1 = dist(p1,p2)\n d2 = dist(p2,p3)\n d3 = dist(p3,p1)\n\n if ((d1.eq.d2).and.(d1.eq.d3)) then\n print *, \"You've got yourself an equilateral triangle.\"\n stop\n elseif ((d1.ne.d2).and.(d2.ne.d3).and.(d3.ne.d1)) then\n print *, \"Scalene it is.\"\n else \n print *, \"Isoceles.\"\n endif\n print *, d1,d2,d3\n if ( (max(d1,d2,d3)**2) /100 .eq. (d1**2+d2**2+d3**2-max(d1,d2,d3)**2) /100) then\n !check for right triangle, divide by 100 to reduce precision as some precision gets lost in sqrt.\n print *, \"|\\\"\n print *, \"| \\\"\n print *, \"| \\\"\n print *, \"|_ \\\"\n print *, \"|_|__\\\"\n endif\n \n\nend program triangle\n\nfunction dist(pt1,pt2)\n implicit none\n real::dist\n real, dimension(2) :: pt1,pt2\n dist = sqrt((pt1(1)-pt2(1))**2+(pt1(2)-pt2(2))**2)\nend function dist\n", "meta": {"hexsha": "c972d8922f061c72e8a8b915b3a0e6ea0b14852f", "size": 1240, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "triangletree.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": "triangletree.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": "triangletree.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": 28.1818181818, "max_line_length": 105, "alphanum_fraction": 0.5790322581, "num_tokens": 413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.8092574754713988}} {"text": "C*********************************************************************C\nC* *C\nC* chapman.for *C\nC* *C\nC* Written by: David L. Huestis, Molecular Physics Laboratory *C\nC* *C\nC* Copyright (c) 2000 SRI International *C\nC* All Rights Reserved *C\nC* *C\nC* This software is provided on an as is basis; without any *C\nC* warranty; without the implied warranty of merchantability or *C\nC* fitness for a particular purpose. *C\nC* *C\nC*********************************************************************C\nC*\nC*\tTo calculate the Chapman Function, Ch(X,chi0), the column\nC*\tdepth of an exponential atmosphere integrated along a line\nC*\tfrom a given point to the sun, divided by the column depth for\nC*\ta vertical sun.\nC*\nC* USAGE:\nC*\nC*\t z = altitude above the surface\nC*\t R = radius of the planet\nC*\t H = atmospheric scale height\nC*\nC*\t X = (R+z)/H\nC*\t chi0 = solar zenith angle (in degrees)\nC*\nC*\t implicit real*4(a-h,o-z)\nC*\t depth = atm_chapman(X,chi0)\t! analytical\nC*\t depth = atm_chap_num(X,chi0)\t! numerical (chi0 .le. 90)\nC*\nC*\t implicit real*8(a-h,o-z)\nC*\t depth = atm8_chapman(X,chi0)\t! analytical\nC*\t depth = atm8_chap_num(X,chi0)\t! numerical (chi0 .le. 90)\nC*\nC* PERFORMANCE:\nC*\nC*\tCompiled and linked using Microsoft FORTRAN 5.1, and executed\nC*\tin MS-DOS mode under Windows 95 on a 160 MHz PC.\nC*\nC* TIMING (in microseconds, typical)\nC*\nC*\t 120\tatm_chapman and atm8_chapman for X .lt. 36\nC*\t 25\tatm_chapman and atm8_chapman for X .ge. 36\nC*\t 500\tatm_chap_num\nC*\t 5000\tatm8_chap_num\nC*\nC* ACCURACY (maximum relative error, 0.le.chi0.le.90, 1.le.X.le.820)\nC*\nC*\t6.0E-7\tatm_chapman and atm8_chapman for X .lt. 60\nC*\t1.5E-7\tatm_chapman and atm8_chapman for X .ge. 60\nC*\t6.0E-8\tatm_chap_num\nC*\t1.E-15\tatm8_chap_num (convergence test)\nC*\nC* CODING\nC*\nC*\tNo claims are made that the code is optimized for speed,\nC*\taccuracy, or compactness. The principal objectives were\nC*\nC*\t (1) Robustness with respect to argument values\nC*\t (2) Rigorous mathematical derivation and error control\nC*\t (3) Maximal use of \"well known\" mathematical functions\nC*\t (4) Ease of readability and mapping of theory to coding\nC*\nC*\tThe real*8 accuracy could be improved with more accurate\nC*\trepresentations of E1(), erfc(), I0(), I1(), K0(), K1().\nC*\nC*\tIn the course of development, many representations and\nC*\tapproximations of the Chapman Function were attempted that\nC*\tfailed to be robustly extendable to machine-precision.\nC*\nC* INTERNET ACCESS:\nC*\nC*\tSource: http://www-mpl.sri.com/software/chapman/chapman.html\nC*\tAuthor: mailto:david.huestis@sri.com\nC*\t http://www-mpl.sri.com/bios/Huestis-DL.html\nC*\nC* EDIT HISTORY:\nC*\nC*\t01/22/2000 DLH\tFirst complete documentation\nC*\nC*\t01/15/2000 DLH\tFirst complete version of chapman.for\nC*\nC**********************************************************************\nC*\nC* THEORY:\nC*\nC* INTRODUCTION\nC*\nC*\t This computer code models the absorption of solar radiation\nC*\tby an atmosphere that depends exponentionally on altitude. In\nC*\tspecific we calculate the effective column depth of a species\nC*\tof local density, n(z), from a point at a given altitude, z0,\nC*\tto the sun at a given solar zenith angle, chi0. Following Rees\nC*\t[Re89, Section 2.2] we write the column depth for chi0 .le. 90\nC*\tdegrees as\nC*\nC* (A) N(z0,chi0) = int{z=z0,infinity}\nC*\t [ n(z)/sqrt( 1 - ( sin(chi0) * (R+z0) / (R+z) ) **2 ) dz ]\nC*\nC*\twhere R is the radius of the solid planet (e.g. Earth). For\nC*\tchi0 .gt. 90 degrees we write\nC*\nC*\t N(z0,chi0) = 2*N(zs,90) - N(z0,180-chi0)\nC*\nC*\twhere zs = (R+z0)*sin(chi0)-R is the tangent height.\nC*\nC*\t For an exponential atmosphere, with\nC*\nC*\t n(z) = n(z0) * exp(-(z-z0)/H)\nC*\nC*\twith a constant scale height, H, the column depth can be\nC*\trepresented by the Chapman function, Ch(X,chi0), named after\nC*\tthe author of the first quantitative mathematical investigation\nC*\t[Ch31b] trough the relation\nC*\nC*\t N(z0,chi0) = H * n(z0) * Ch(X,chi0)\nC*\nC*\twhere X = (R+z0)/H is a dimensionless measure of the radius\nC*\tof curvature, with values from about 300 to 1300 on Earth.\nC*\nC*\nC* APPROACH\nC*\nC*\t We provide function entry points for very stable and\nC*\treasonably efficient evaluation of Ch(X,chi0) with full\nC*\tsingle-precision accuracy (.le. 6.0E-7 relative) for a wide\nC*\trange of parameters. A 15-digit-accurate double precision\nC*\tnumerical integration routine is also provided.\nC*\nC*\t Below we will develop (1) a compact asymptotic expansion of\nC*\tgood accuracy for moderately large values of X (.gt. 36) and all\nC*\tvalues of chi0, (2) an efficient numerical integral for\nC*\tall values of X and chi0, and (3) an explicit analytical\nC*\trepresentation, valid for all values of X and chi0, based\nC*\tthe differential equation satisfied by Ch(X,chi0).\nC*\nC*\t All three of these represent new research results as well\nC*\tas significant computational improvements over the previous\nC*\tliterature, much of which is cited below.\nC*\nC*\nC* CHANGES OF THE VARIABLE OF INTEGRATION\nC*\nC*\tSubstituting y = (R+z)/(R+z0) - 1 we find\nC*\nC* (B) Ch(X,chi0) = X * int{y=0,infinity}\nC*\t [ exp(-X*y) / sqrt( 1 - ( sin(chi0) / (1+y) )**2 ) dy ]\nC*\nC*\tThe futher substitutions s = (1+y)/sin(chi0), s0 = 1/sin(chi0)\nC*\tgive\nC*\nC* (C) Ch(X,chi0) = X*sin(chi0) * int{s=s0,infinity}\nC*\t [ exp(X*(1-sin(chi0)*s)) * s / sqrt(s**2-1) ds ]\nC*\nC*\tFrom this equation we can establish that\nC*\nC*\t Ch(X,90) = X*exp(X)*K1(X)\nC*\nC*\t[AS64, Equations 9.6.23 and 9.6.27]. If we now substitute\nC*\ts = 1/sin(lambda) we obtain\nC*\nC* (D) Ch(X,chi0) = X*sin(chi0) * int{lambda=0,chi0}\nC*\t [ exp(X*(1-sin(chi0)*csc(lambda))) * csc(lambda)**2 dlambda]\nC*\nC*\twhich is the same as Chapman's original formulation [Ch31b, p486,\nC*\teqn (10)]. If we first expand the square root in (B)\nC*\nC*\t 1/sqrt(1-q) = 1 + q/( sqrt(1-q)*(1+sqrt(1-q)) )\nC*\nC*\twith q = ( sin(chi0) / (1+y) )**2 = sin(lambda)**2, we obtain\nC*\ta new form of (D) without numerical sigularities and simple\nC*\tconvergence to Ch(0,chi0) = Ch(X,0) = 1\nC*\nC* (E) Ch(X,chi0) = 1 + X*sin(chi0) * int{lambda=0,chi0}\nC*\t [ exp(X*(1-sin(chi0)*csc(lambda)))\nC*\t\t/ (1 + cos(lambda) ) dlambda ]\nC*\nC*\tAlternatively, we may substitute t**2 = y + t0**2,\nC*\tinto Equation (B), with t0**2 = 1-sin(chi0), finding\nC*\nC* (F) Ch(X,chi0) = X * int{s=t0,infinity}\nC*\t [ exp(-X*(t**2-t0**2)) * f(t,chi0) dt ]\nC*\nC*\twhere\nC*\nC*\t f(t,chi0) = (t**2 + sin(chi0)) / sqrt(t**2+2*sin(chi0))\nC*\nC*\t f(t,chi0) = (t**2-t0**2+1)/sqrt(t**2-t0**2+1+sin(chi0))\nC*\nC*\t Below we will use Equation (F) above to develop a\nC*\tcompact asymptotic expansion of good accuracy for moderately\nC*\tlarge values of X (.gt. 36) and all values of chi0, Equation (E)\nC*\tto develop an efficient numerical integral for Ch(X,chi0) for\nC*\tall values of X and chi0, and Equation (C) to derive an explicit\nC*\tanalytical representation, valid for all values of X and chi0,\nC*\tbased on the differential equation satisfied by Ch(X,chi0).\nC*\nC* atm_chapman(X,chi0) and atm8_chapman(X,chi0)\nC*\nC*\tThese routines return real*4 and real*8 values of Ch(X,chi0)\nC*\tselecting the asymptotic expansion or differential equation\nC*\tapproaches, depending on the value of X. These routines also\nC*\thandle the case of chi0 .gt. 90 degrees.\nC*\nC* atm_chap_num(X,chi0) and atm8_chap_num(X,chi0)\nC*\nC*\tThese routines return real*4 and real*8 values of Ch(X,chi0)\nC*\tevaluated numerically. They are both more accurate than the\nC*\tcorresponding atm*_chapman() functions, but take significantly\nC*\tmore CPU time.\nC*\nC*\nC* ASYMPTOTIC EXPANSION\nC*\nC*\tFrom Equation (F) we expand, with t0**2 = 1-sin(chi0),\nC*\nC*\t f(t,chi0) = sum{n=0,3} [ C(n,chi0) * (t**2-t0**2)**n ]\nC*\nC*\tThe function atm8_chap_asy(X,chi0) evaluates integrals of the\nC*\tform\nC*\nC*\t int{t=t0,infinity} [exp(-X*(t**2-t0**2))*(t**2-t0**2)**n dt]\nC*\nC*\tin terms of incomplete gamma functions, and sums them to\nC*\tcompute Ch(X,chi0). For large values of X, this results in an\nC*\tasymptotic expansion in negative powers of X, with coefficients\nC*\tthat are stable for all values of chi0.\nC*\nC*\tIn contrast, the asymptotic expansions of Chapman [Ch31b,\nC*\tp488, Equation (22) and p490, Equation (38)], Hulburt [He39],\nC*\tand Swider [Sw64, p777, Equation (43)] use negative powers of\nC*\tX*cos(chi0)**2 or X*sin(chi0), and are accurate only for\nC*\tsmall values or large values of chi0, respectively.\nC*\nC*\tTaking only the first term in the present expansion gives the\nC*\tsimple formula\nC*\nC*\t Ch(X,chi0) = sqrt(pi*X/(1+sin(chi0))) * exp(X*(1-sin(chi0)))\nC*\t\t* erfc( sqrt(X*(1-sin(chi0))) )\nC*\nC*\tThis is slightly more accurate than the semiempirical\nC*\tformula of Fitzmaurice [Fi64, Equation (3)], and sightly less\nC*\taccurate than that of Swider [Sw64, p780, Equation (52),\nC*\tcorrected in SG69].\nC*\nC*\nC* NUMERICAL INTEGRATION\nC*\nC*\tWe are integrating\nC*\nC* (E) Ch(X,chi0) = 1 + X*sin(chi0) * int{lambda=0,chi0}\nC*\t [ exp(X*(1-sin(chi0)*csc(lambda)))\nC*\t\t/ ( 1 + cos(lambda) ) dlambda ]\nC*\nC*\tThe integrand is numerically very smooth, and rapidly varying\nC*\tonly near lambda = 0. For X .ne. 0 we choose the lower limit\nC*\tof numerical integration such that the integrand is\nC*\texponentially small, 7.0E-13 (3.0E-20 for real*8). The domain\nC*\tof integration is divided into 64 equal intervals (6000 for\nC*\treal*8), and integrated numerically using the 9-point closed\nC*\tNewton-Cotes formula from Hildebrand [Hi56a, page 75, Equation\nC*\t(3.5.17)].\nC*\nC*\nC* INHOMOGENOUS DIFFERENTIAL EQUATION\nC*\nC*\t The function atm8_chap_deq(X,chi0) calculates Ch(X,chi0),\nC*\tbased on Equation (C) above, using the inhomogeneous\nC*\tBessel's equation as described below. Consider the function\nC*\nC*\t Z(Q) = int{s=s0,infinity} [ exp(-Q*s) / sqrt(s**2-1) ds ]\nC*\nC*\tDifferentiating with respect to Q we find that\nC*\nC*\t Ch(X,chi0) = - Q * exp(X) * d/dQ [ Z(Q) ]\nC*\nC*\twith Q = X*sin(chi0), s0 = 1/sin(chi0). Differentiating\nC*\tinside the integral, we find that\nC*\nC*\t Z\"(Q) + Z'(Q)/Q - Z(Q) = sqrt(s0**2-1) * exp(-Q*s0) / Q\nC*\nC*\tgiving us an inhomogeneous modified Bessel's equation of order\nC*\tzero. Following Rabenstein [Ra66, pp43-45,149] the solution\nC*\tof this equation can be written as\nC*\nC*\t Z(Q) = A*I0(Q) + B*K0(Q) - sqrt(s0**2-1)\nC*\t * int{t=Q,infinity} [ exp(-t*s0)\nC*\t\t * ( I0(Q)*K0(t) - I0(t)*K0(Q) ) dt ]\nC*\nC*\twith coefficients A and B to be determined by matching\nC*\tboundary conditions.\nC*\nC*\t Differentiating with respect to Q we obtain\nC*\nC*\t Ch(X,chi0) = X*sin(chi0)*exp(X)*(\nC*\t\t- A*I1(X*sin(chi0)) + B*K1(X*sin(chi0))\nC*\t\t+ cos(chi0) * int{y=X,infinity} [ exp(-y)\nC*\t\t * ( I1(X*sin(chi0))*K0(y*sin(chi0))\nC*\t\t + K1(X*sin(chi0))*I0(y*sin(chi0)) ) dy ] )\nC*\nC*\tApplying the boundary condition Ch(X,0) = 1 requires that\nC*\tB = 0. Similarly, the requirement that Ch(X,chi0) approach\nC*\tthe finite value of sec(chi0) as X approaches infinity [Ch31b,\nC*\tp486, Equation (12)] implies A = 0. Thus we have\nC*\nC*\t Ch(X,chi0) = X*sin(chi0)*cos(chi0)*exp(X)*\nC*\t\tint{y=X,infinity} [ exp(-y)\nC*\t\t * ( I1(X*sin(chi0))*K0(y*sin(chi0))\nC*\t\t + K1(X*sin(chi0))*I0(y*sin(chi0)) ) dy ]\nC*\nC*\tThe function atm8_chap_deq(X,chi0) evaluates this expression.\nC*\tSince explicit approximations are available for I1(z) and K1(z),\nC*\tthe remaining challenge is evaluation of the integrals\nC*\nC*\t int{y=X,infinity} [ exp(-y) I0(y*sin(chi0)) dy ]\nC*\nC*\tand\nC*\nC*\t int{y=X,infinity} [ exp(-y) K0(y*sin(chi0)) dy ]\nC*\nC*\twhich are accomplished by term-by-term integration of ascending\nC*\tand descending power series expansions of I0(z) and K0(z).\nC*\nC* REFERENCES:\nC*\nC*\tAS64\tM. Abramowitz and I. A. Stegun, \"Handbook of\nC*\t\tMathematical Functions,\" NBS AMS 55 (USGPO,\nC*\t\tWashington, DC, June 1964, 9th printing, November 1970).\nC*\nC*\tCh31b\tS. Chapman, \"The Absorption and Dissociative or\nC*\t\tIonizing Effect of Monochromatic Radiation in an\nC*\t\tAtmosphere on a Rotating Earth: Part II. Grazing\nC*\t\tIncidence,\" Proc. Phys. Soc. (London), _43_, 483-501\nC*\t\t(1931).\nC*\nC*\tFi64\tJ. A. Fitzmaurice, \"Simplfication of the Chapman\nC*\t\tFunction for Atmospheric Attenuation,\" Appl. Opt. _3_,\nC*\t\t640 (1964).\nC*\nC*\tHi56a\tF. B. Hildebrand, \"Introduction to Numerical\nC*\t\tAnalysis,\" (McGraw-Hill, New York, 1956).\nC*\nC*\tHu39\tE. O. Hulburt, \"The E Region of the Ionosphere,\"\nC*\t\tPhys. Rev. _55_, 639-645 (1939).\nC*\nC*\tPFT86\tW. H. Press, B. P. Flannery, S. A. Teukolsky, and\nC*\t\tW. T. Vetterling, \"Numerical Recipes,\" (Cambridge,\nC*\t\t1986).\nC*\nC*\tRa66\tA. L. Rabenstein, \"Introduction to Ordinary\nC*\t\tDifferential Equations,\" (Academic, NY, 1966).\nC*\nC*\tRe89\tM. H. Rees, \"Physics and Chemistry of the Upper\nC*\t\tAtmosphere,\" (Cambridge, 1989).\nC*\nC*\tSG69\tW. Swider, Jr., and M. E. Gardner, \"On the Accuracy\nC*\t\tof Chapman Function Approximations,\" Appl. Opt. _8_,\nC*\t\t725 (1969).\nC*\nC*\tSw64\tW. Swider, Jr., \"The Determination of the Optical\nC*\t\tDepth at Large Solar Zenith Angles,\" Planet. Space\nC*\t\tSci. _12_, 761-782 (1964).\nC\nC ####################################################################\nC\nC\tChapman function calculated by various methods\nC\nC\t Ch(X,chi0) = atm_chapman(X,chi0) : real*4 entry\nC\t Ch(X,chi0) = atm8_chapman(X,chi0) : real*8 entry\nC\nC\tInternal service routines - user should not call, except for\nC\ttesting.\nC\nC\t Ch(X,chi0) = atm8_chap_asy(X,chi0) : asymptotic expansion\nC\t Ch(X,chi0) = atm8_chap_deq(X,chi0) : differential equation\nC\t Ch(X,chi0) = atm_chap_num(X,chi0) : real*4 numerical integral\nC\t Ch(X,chi0) = atm8_chap_num(X,chi0) : real*8 numerical integral\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThese are the entries for the user to call.\nC\nC\tchi0 can range from 0 to 180 in degrees. For chi0 .gt. 90, the\nC\tproduct X*(1-sin(chi0)) must not be too large, otherwise we\nC\twill get an exponential overflow.\nC\nC\tFor chi0 .le. 90 degrees, X can range from 0 to thousands\nC\twithout overflow.\nC\nC ====================================================================\n\n\treal*4 function atm_chapman( X, chi0 )\n\treal*8 atm8_chapman\n\tatm_chapman = atm8_chapman( dble(X), dble(chi0) )\n\treturn\n\tend\n\nC ====================================================================\n\n\treal*8 function atm8_chapman( X, chi0 )\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768d0)\n\n\tif( (X .le. 0) .or. (chi0 .le. 0) .or. (chi0 .ge. 180) ) then\n\t atm8_chapman = 1\n\t return\n\tend if\n\n\tif( chi0 .gt. 90 ) then\n\t chi = 180 - chi0\n\telse\n\t chi = chi0\n\tend if\n\n\tif( X .lt. 36 ) then\n\t atm8_chapman = atm8_chap_deq(X,chi)\n\telse\n\t atm8_chapman = atm8_chap_asy(X,chi)\n\tend if\n\n\tif( chi0 .gt. 90 ) then\n\t atm8_chapman = 2*exp(X*2*sin((90-chi)/(2*rad))**2)\n *\t\t* atm8_chap_xK1(X*sin(chi/rad)) - atm8_chapman\n\tend if\n\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Chapman function routine calculates\nC\nC\t Ch(X,chi0) = atm8_chap_asy(X,chi0)\nC\t\t = sum{n=0,3} [C(n) * int{t=t0,infinity}\nC\t\t\t[ exp(-X*(t**2-t0**2) * (t**2-t0**2)**n dy ] ]\nC\nC\twith t0**2 = 1 - sin(chi0)\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_asy( X, chi0 )\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768d0)\n\tdimension C(0:3), XI(0:3), Dn(0:3)\n\tcommon/atm8_chap_cm/Fn(0:3)\n\n\tif( (X .le. 0) .or. (chi0 .le. 0) ) then\n\t do i=0,3\n\t Fn(i) = 1\n\t end do\n\t go to 900\n\tend if\n\n\tsinchi = sin(chi0/rad)\n\ts1 = 1 + sinchi\n\trx = sqrt(X)\n\tY0 = rx * sqrt( 2*sin( (90-chi0)/(2*rad) )**2 )\n\n\tC(0) = 1/sqrt(s1)\n\tfact = C(0)/s1\n\tC(1) = fact * (0.5d0+sinchi)\n\tfact = fact/s1\n\tC(2) = - fact * (0.125d0+0.5d0*sinchi)\n\tfact = fact/s1\n\tC(3) = fact * (0.0625d0+0.375d0*sinchi)\n\n\tcall atm8_chap_gd3( Y0, Dn )\n\tfact = 2*rx\n\tdo n=0,3\n\t XI(n) = fact * Dn(n)\n\t fact = fact/X\n\tend do\n\n\tFn(0) = C(0) * XI(0)\n\tdo i=1,3\n\t Fn(i) = Fn(i-1) + C(i)*XI(i)\n\tend do\n\n900\tatm8_chap_asy = Fn(3)\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Chapman function routine calculates\nC\nC\t Ch(X,chi0) = atm8_chap_deq(X,chi0)\nC\t\t = X * sin(chi0) * cos(chi0) * exp(X*sin(chi0))\nC\t\t * int{y=X,infinity} [ exp(-y)*(\nC\t\t\t I1(X*sin(chi0))*K0(y*sin(chi0))\nC\t\t\t + K1(X*sin(chi0))*I0(y*sin(chi0)) ) dy ]\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_deq( X, chi0 )\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768d0)\n\tcommon/atm8_chap_cm/xI1,xK1,yI0,yK0\n\n\tif( (X .le. 0) .or. (chi0 .le. 0) ) go to 800\n\talpha = X * sin(chi0/rad)\n\nC --------------------------------------------------------------------\nC\nC\tThis code fragment calculates\nC\nC\t yI0 = exp(x*(1-sin(chi0))) * cos(chi0) *\nC\t\tint{y=x,infinity} [ exp(-y) * I0(y*sin(chi0)) dy ]\nC\nC --------------------------------------------------------------------\n\n\tyI0 = atm8_chap_yI0( X, chi0 )\n\nC --------------------------------------------------------------------\nC\nC\tThis code fragment calculates\nC\nC\t yK0 = exp(x*(1+sin(chi0))) x * sin(chi0) * cos(chi0) *\nC\t\tint{y=x,infinity} [ exp(-y) * K0(y*sin(chi0)) dy ]\nC\nC --------------------------------------------------------------------\n\n\tyK0 = atm8_chap_yK0( X, chi0 )\n\nC --------------------------------------------------------------------\nC\nC\tThis code fragment calculates\nC\nC\t xI1 = exp(-x*sin(chi0)) * I1(x*sin(chi0))\nC\nC --------------------------------------------------------------------\n\n\txI1 = atm8_chap_xI1( alpha )\n\nC --------------------------------------------------------------------\nC\nC\tThis code fragment calculates\nC\nC\t xK1 = x*sin(chi0) * exp(x*sin(chi0)) * K1(x*sin(chi0))\nC\nC --------------------------------------------------------------------\n\n\txK1 = atm8_chap_xK1( alpha )\n\nC --------------------------------------------------------------------\nC\nC\tCombine the terms\nC\nC --------------------------------------------------------------------\n\n\tatm8_chap_deq = xI1*yK0 + xK1*yI0\n\tgo to 900\n\n800\tatm8_chap_deq = 1\n900\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Chapman function routine calculates\nC\nC\t Ch(X,chi0) = atm_chap_num(X,chi0) = numerical integral\nC\nC ====================================================================\n\n\treal*4 function atm_chap_num(X,chi0)\n\timplicit real*8(a-h,o-z)\n\treal*4 X, chi0\n\tparameter (rad=57.2957795130823208768D0)\n\tparameter (n=65,nfact=8)\n\tdimension factor(0:nfact)\n\tdata factor/14175.0D0, 23552.0D0, -3712.0D0, 41984.0D0,\n *\t -18160.0D0, 41984.0D0, -3712.0D0, 23552.0D0, 7912.0D0/\n\n\tif( (chi0 .le. 0) .or. (chi0 .gt. 90) .or. (X .le. 0) ) then\n\t atm_chap_num = 1\n\t return\n\tend if\n\n\tX8 = X\n\tchi0rad = chi0/rad\n\tsinchi = sin(chi0rad)\n\n\talpha0 = asin( (X8/(X8+28)) * sinchi )\n\tdelta = (chi0rad - alpha0)/(n-1)\n\n\tsum = 0\n\n\tdo i=1,n\n\t alpha = -(i-1)*delta + chi0rad\n\n\t if( (i .eq. 1) .or. (X .le. 0) ) then\n\t f = 1/(1+cos(alpha))\n\t else if( alpha .le. 0 ) then\n\t f = 0\n\t else\n\t f = exp(-X8*(sinchi/sin(alpha)-1) ) /(1+cos(alpha))\n\t end if\n\n\t if( (i.eq.1) .or. (i.eq.n) ) then\n\t fact = factor(nfact)/2\n\t else\n\t fact = factor( mod(i-2,nfact)+1 )\n\t end if\n\n\t sum = sum + fact*f\n\tend do\n\n\tatm_chap_num = 1 + X8*sinchi*sum*delta/factor(0)\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Chapman function routine calculates\nC\nC\t Ch(X,chi0) = atm8_chap_num(X,chi0) = numerical integral\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_num(X,chi0)\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768D0)\n\tparameter (n=601,nfact=8)\n\tdimension factor(0:nfact)\n\tdata factor/14175.0D0, 23552.0D0, -3712.0D0, 41984.0D0,\n *\t -18160.0D0, 41984.0D0, -3712.0D0, 23552.0D0, 7912.0D0/\n\n\tif( (chi0 .le. 0) .or. (chi0 .gt. 90) .or. (X .le. 0) ) then\n\t atm8_chap_num = 1\n\t return\n\tend if\n\n\tchi0rad = chi0/rad\n\tsinchi = sin(chi0rad)\n\n\talpha0 = asin( (X/(X+45)) * sinchi )\n\tdelta = (chi0rad - alpha0)/(n-1)\n\n\tsum = 0\n\n\tdo i=1,n\n\t alpha = -(i-1)*delta + chi0rad\n\n\t if( (i .eq. 1) .or. (X .le. 0) ) then\n\t f = 1/(1+cos(alpha))\n\t else if( alpha .le. 0 ) then\n\t f = 0\n\t else\n\t f = exp(-X*(sinchi/sin(alpha)-1) ) /(1+cos(alpha))\n\t end if\n\n\t if( (i.eq.1) .or. (i.eq.n) ) then\n\t fact = factor(nfact)/2\n\t else\n\t fact = factor( mod(i-2,nfact)+1 )\n\t end if\n\n\t sum = sum + fact*f\n\tend do\n\n\tatm8_chap_num = 1 + X*sinchi*sum*delta/factor(0)\n\treturn\n\tend\n\nC ####################################################################\nC\nC\tThe following \"Bessel integral\" routines return various\nC\tcombinations of integrals of Bessel functions, powers,\nC\tand exponentials, involving trigonometric functions of chi0.\nC\nC\tFor small values of z = X*sin(chi0) we expand\nC\nC\t I0(z) = sum{n=0,6} [ aI0(n) * z**(2*n) ]\nC\t K0(z) = -log(z)*I0(z) + sum{n=0,6} [ aK0(n) * z**(2*n) ]\nC\nC\tFor large values of z we expand in reciprocal powers\nC\nC\t I0(z) = exp(z) * sum{n=0,8} [ bI0(n) * z**(-n-0.5) ]\nC\t K0(z) = exp(-z) * sum{n=0,6} [ bK0(n) * z**(-n-0.5) ]\nC\nC\tThe expansion coefficients are calculated from those given\nC\tby Abramowitz and Stegun [AS64, pp378-9, Section 9.8] and\nC\tPress et al. [PFT86, pp177-8, BESSI0.FOR, BESSK0.FOR].\nC\nC\tFor small values of X*sin(chi0) we break the integral\nC\tinto two parts (with F(z) = I0(z) or K0(z)):\nC\nC\t int{y=X,infinity} [ exp(-y) * F(y*sin(chi0)) dy ]\nC\nC\t = int{y=X,x1} [ exp(-y) * F(y*sin(chi0)) dy ]\nC\t + int{y=x1,infinity} [ exp(-y) * F(y*sin(chi0)) dy ]\nC\nC\twhere x1 = 3.75/sin(chi0) for I0 and 2/sin(chi0) for K0.\nC\nC\tIn the range y=X,x1 we integrate the term-by-term using\nC\nC\t int{z=a,b} [ exp(-z) * z**(2*n) dz ]\nC\t = Gamma(2*n+1,a) - Gamma(2*n+1,b)\nC\nC\tand a similar but more complicated formula for\nC\nC\t int{z=a,b} [ log(z) * exp(-z) * z**(2*n) dz ]\nC\nC\tIn the range y=x1,infinity we use\nC\nC\t int{z=b,infinity} [ exp(-z) * z**(-n-0.5) dz]\nC\t = Gamma(-n+0.5,b)\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThis Bessel integral routine calculates\nC\nC\t yI0 = exp(X*(1-sin(chi0))) * cos(chi0) *\nC\t\tint{y=X,infinity} [ exp(-y) * I0(y*sin(chi0)) dy ]\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_yI0( X, chi0 )\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768d0)\n\tdimension qbeta(0:8), gg(0:6)\n\tdimension aI0(0:6), bI0(0:8)\n\n data aI0/ 1.0000000D+00, 2.4999985D-01, 1.5625190D-02,\n * 4.3393973D-04, 6.8012343D-06, 6.5601736D-08,\n * 5.9239791D-10/\n data bI0/ 3.9894228D-01, 4.9822200D-02, 3.1685484D-02,\n * -8.3090918D-02, 1.8119815D+00,-1.5259477D+01,\n * 7.3292025D+01,-1.7182223D+02, 1.5344533D+02/\n\n\ttheta = (90-chi0)/(2*rad)\n\tsint = sin(theta)\n\tcost = cos(theta)\n\tsinchi = sin(chi0/rad)\n\tcoschi = cos(chi0/rad)\n\tsc1m = 2*sint**2\t! = (1-sinchi)\n\n\talpha = X * sinchi\n\n\tif( alpha .le. 0 ) then\n\t atm8_chap_yI0 = 1\n\telse if( alpha .lt. 3.75d0 ) then\n\t x1 = 3.75d0/sinchi\n\t call atm8_chap_gg06( X, x1, gg )\n\t if( X .le. 1 ) then\n\t rho = 1\n\t else\n\t rho = 1/X\n\t end if\n\t f = (sinchi/rho)**2\n\t sum = aI0(6)*gg(6)\n\t do i=5,0,-1\n\t sum = sum*f + aI0(i)*gg(i)\nC\t write(*,1900)i,sum,gg(i)\nC1900\tformat(i5,1p5d14.6)\n\t end do\n\t call atm8_chap_gq85( x1*sc1m, qbeta )\n\t sum2 = bI0(8) * qbeta(8)\n\t do n=7,0,-1\n\t sum2 = sum2/3.75d0 + bI0(n)*qbeta(n)\n\t end do\n\t atm8_chap_yI0 = exp(-alpha)*coschi*sum\n *\t\t+ exp((X-x1)*sc1m)*sum2*cost*sqrt(2/sinchi)\n\telse\n\t call atm8_chap_gq85( X*sc1m, qbeta )\n\t sum = bI0(8) * qbeta(8)\n\t do n=7,0,-1\n\t sum = sum/alpha + bI0(n)*qbeta(n)\n\t end do\n\t atm8_chap_yI0 = sum * cost * sqrt( 2 / sinchi )\n\tend if\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Bessel integral routine calculates\nC\nC\t yK0 = exp(x*(1+sin(chi0))) x * sin(chi0) * cos(chi0) *\nC\t\tint{y=x,infinity} [ exp(-y) * K0(y*sin(chi0)) dy ]\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_yK0( x, chi0 )\n\timplicit real*8(a-h,o-z)\n\tparameter (rad=57.2957795130823208768d0)\n\tdimension aI0(0:6), aK0(0:6), bK0(0:6)\n\tdimension gf(0:6), gg(0:6), qgamma(0:8)\n\n data aI0/ 1.0000000D+00, 2.4999985D-01, 1.5625190D-02,\n * 4.3393973D-04, 6.8012343D-06, 6.5601736D-08,\n * 5.9239791D-10/\n data aK0/ 1.1593152D-01, 2.7898274D-01, 2.5249154D-02,\n * 8.4587629D-04, 1.4975897D-05, 1.5045213D-07,\n * 2.2172596D-09/\n data bK0/ 1.2533141D+00,-1.5664716D-01, 8.7582720D-02,\n * -8.4995680D-02, 9.4059520D-02,-8.0492800D-02,\n * 3.4053120D-02/\n\n\ttheta = (90-chi0)/(2*rad)\n\tsint = sin(theta)\n\tcost = cos(theta)\n\tsinchi = sin(chi0/rad)\n\tsc1 = 1+sinchi\n\tcoschi = sin(2*theta)\n\n\talpha = X * sinchi\n\tgamma = X * sc1\n\n\tif( alpha .le. 0 ) then\n\t atm8_chap_yK0 = 0\n\telse if( alpha .lt. 2 ) then\n\t x1 = 2/sinchi\n\t call atm8_chap_gfg06( X, x1, gf, gg )\n\t if( x .le. 1 ) then\n\t rho = 1\n\t else\n\t rho = 1/X\n\t end if\n\t sl = log(sinchi)\n\t f = (sinchi/rho)**2\n\t sum = -aI0(6)*gf(6) + (-sl*aI0(6)+aK0(6))*gg(6)\n\t do i=5,0,-1\n\t sum = sum*f - aI0(i)*gf(i) + (-sl*aI0(i)+aK0(i))*gg(i)\nC\t write(*,1900)i,sum,gf(i),gg(i)\nC1900\tformat(i5,1p5d14.6)\n\t end do\n\t call atm8_chap_gq85( x1*sc1, qgamma )\n\t sum2 = bK0(6)*qgamma(6)\n\t do i=5,0,-1\n\t sum2 = sum2*0.5d0 + bK0(i)*qgamma(i)\nC\t write(*,1900)i,sum2,bK0(i),qgamma(i)\n\t end do\n\t sum = sum + exp(X-x1-2)*sum2/sqrt(sinchi*sc1)\n\t atm8_chap_yK0 = sum * exp(alpha) * alpha * coschi\n\telse\n\t call atm8_chap_gq85( gamma, qgamma )\n\t sum = bK0(6) * qgamma(6)\n\t do i=5,0,-1\n\t sum = sum/alpha + bK0(i)*qgamma(i)\n\t end do\n\t atm8_chap_yK0 = sum * sint * sqrt( 2 * sinchi ) * X\n\tend if\n\n\treturn\n\tend\n\nC ####################################################################\nC\nC\tThe following \"pure math\" routines return various combinations\nC\tof Bessel functions, powers, and exponentials.\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThis Bessel function math routine returns\nC\nC\t xI1 = exp(-|z|) * I1(z)\nC\nC\tFollowing Press et al [PFT86, page 178, BESSI1.FOR] and\nC\tAbrahamson and Stegun [AS64, page 378, 9.8.3, 9.8.4].\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_xI1( z )\n\timplicit real*8(a-h,o-z)\n dimension aI1(0:6), bI1(0:8)\n\n data aI1/ 5.00000000D-01, 6.2499978D-02, 2.6041897D-03,\n * 5.4244512D-05, 6.7986797D-07, 5.4830314D-09,\n * 4.1909957D-11/\n data bI1/ 3.98942280D-01,-1.4955090D-01,-5.0908781D-02,\n * 8.6379434D-02,-2.0399403D+00, 1.6929962D+01,\n * -8.0516146D+01, 1.8642422D+02,-1.6427082D+02/\n\n\tif( z .lt. 0 ) then\n\t az = -z\n\telse if( z .eq. 0 ) then\n\t atm8_chap_xI1 = 0\n\t return\n\telse\n\t az = z\n\tend if\n\tif( az .lt. 3.75d0 ) then\n\t z2 = z*z\n\t sum = aI1(6)\n\t do i=5,0,-1\n\t sum = sum*z2 + aI1(i)\n\t end do\n\t atm8_chap_xI1 = z*exp(-az) * sum\n\telse\n\t sum = bI1(8)\n\t do i=7,0,-1\n\t sum = sum/az + bI1(i)\n\t end do\n\t atm8_chap_xI1 = sum*sqrt(az)/z\n\tend if\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Bessel function math routine returns\nC\nC\t xK1 = z * exp(+z) * K1(z)\nC\nC\tFollowing Press et al [PFT86, page 179, BESSK1.FOR] and\nC\tAbrahamson and Stegun [AS64, page 379, 9.8.7, 9.8.8].\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_xK1( z )\n\timplicit real*8(a-h,o-z)\n dimension aK1(0:6), bK1(0:6)\n\n data aK1/ 1.00000000D+00, 3.8607860D-02,-4.2049112D-02,\n * -2.8370152D-03,-7.4976641D-05,-1.0781641D-06,\n * -1.1440430D-08/\n data bK1/ 1.25331414D+00, 4.6997238D-01,-1.4622480D-01,\n * 1.2034144D-01,-1.2485648D-01, 1.0419648D-01,\n * -4.3676800D-02/\n\n\tif( z .le. 0 ) then\n\t atm8_chap_xK1 = 1\n\telse if( z .lt. 2 ) then\n\t xz = exp(z)\n\t z2 = z*z\n\t sum = aK1(6)\n\t do i=5,0,-1\n\t sum = sum*z2 + aK1(i)\n\t end do\n\t atm8_chap_xK1 = xz * ( sum\n *\t\t+ z*log(z/2)*atm8_chap_xI1(z)*xz )\n\telse\n\t sum = bk1(6)\n\t do i=5,0,-1\n\t sum = sum/z + bK1(i)\n\t end do\n\t atm8_chap_xK1 = sum*sqrt(z)\n\tend if\n\n\treturn\n\tend\n\nC ####################################################################\nC\nC\tThe following \"pure math\" routines return various combinations\nC\tof the Error function, powers, and exponentials.\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThis Error function math routine returns\nC\nC\t xerfc(x) = exp(x**2)*erfc(x)\nC\nC\tfollowing Press et al. [PFT86, p164, ERFCC.FOR]\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_xerfc(x)\n\timplicit real*8(a-h,o-z)\n T=1.0D0/(1.0D0+0.5D0*x)\n\tatm8_chap_xerfc =\n *\t T*EXP( -1.26551223D0 +T*(1.00002368D0 +T*( .37409196D0\n * +T*( .09678418D0 +T*(-.18628806D0 +T*( .27886807D0\n *\t +T*(-1.13520398D0 +T*(1.48851587D0 +T*(-.82215223D0\n *\t +T* .17087277D0) ))))))))\n RETURN\n END\n\nC ####################################################################\nC\nC\tThe following \"pure math\" routines return various combinations\nC\tof Exponential integrals, powers, and exponentials.\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThis Exponential math routine evaluates\nC\nC\t zxE1(x) = x*exp(x) int{y=1,infinity} [ exp(-x*y)/y dy ]\nC\nC\tfollowing Abramowitz and Stegun [AS64, p229;231, equations\nC\t5.1.11 and 5.1.56]\nC\nC ====================================================================\n\n\treal*8 function atm8_chap_zxE1(x)\n\timplicit real*8(a-h,o-z)\n\tparameter (gamma = 0.5772156649015328606d0)\n\tdimension aE1(0:4), bE1(0:4), cEin(1:10)\n\n\tdata aE1/1.0d0, 8.5733287401d0, 18.0590169730d0,\n *\t 8.6347608925d0, 0.2677737343d0 /\n\tdata bE1/1.0d0, 9.5733223454d0, 25.6329561486d0,\n *\t 21.0996530827d0, 3.9584969228d0/\n data cEin/ 1.00000000D+00,-2.50000000D-01, 5.55555556D-02,\n * -1.0416666667D-02, 1.6666666667D-03,-2.3148148148D-04,\n * 2.8344671202D-05,-3.1001984127D-06, 3.0619243582D-07,\n * -2.7557319224D-08/\n\n\tif( x .le. 0 ) then\n\t atm8_chap_zxE1 = 0\n\telse if( x .le. 1 ) then\n\t sum = cEin(10)\n\t do i=9,1,-1\n\t sum = sum*x + cEin(i)\n\t end do\n\t atm8_chap_zxE1 = x*exp(x)*( x * sum - log(x) - gamma )\n\telse\n\t top = aE1(4)\n\t bot = bE1(4)\n\t do i=3,0,-1\n\t top = top/x + aE1(i)\n\t bot = bot/x + bE1(i)\n\t end do\n\t atm8_chap_zxE1 = top/bot\n\tend if\n\treturn\n\tend\n\nC ####################################################################\nC\nC\tThe following \"pure math\" routines return various combinations\nC\tof incomplete gamma functions, powers, and exponentials.\nC\nC ####################################################################\n\nC ====================================================================\nC\nC\tThis gamma function math routine calculates\nC\nC\tDn(n) = int{t=z,infinity}\nC\t\t[ exp( -(t**2-z**2) ) * (t**2-z**2)**n dt ]\nC\nC ====================================================================\n\n\tsubroutine atm8_chap_gd3( z, Dn )\n\timplicit real*8(a-h,o-z)\n\tparameter (rpi=1.7724538509055160273d0)\n\tdimension Dn(0:3), xg(0:3)\n\n\tif( z .le. 0 ) then\n\t Dn(0) = rpi/2\n\t do i=1,3\n\t Dn(i) = (i-0.5d0)*Dn(i-1)\n\t end do\n\t return\n\tend if\n\n\tz2 = z*z\n\tif( z .ge. 7 ) r = 1/z2\n\n\tif( z .lt. 14 ) then\n\t z4 = z2*z2\n\t xg(0) = rpi * atm8_chap_xerfc(z)\n\t xg(1) = 0.5d0*xg(0) + z\n\t xg(2) = 1.5d0*xg(1) + z*z2\n\t Dn(0) = 0.5d0*xg(0)\n\t Dn(1) = 0.5d0*(xg(1)-z2*xg(0))\n\t Dn(2) = 0.5d0*(xg(2)-2*z2*xg(1)+z4*xg(0))\n\telse\n\t Dn(0) = ( 1 + r*(-0.5d0 +r*(0.75d0 +r*(-1.875d0\n *\t\t+r*6.5625d0) ) ) )/(2*z)\n\t Dn(1) = ( 1 + r*(-1.0d0 +r*(2.25d0 +r*(-7.5d0\n *\t\t+r*32.8125d0) ) ) )/(2*z)\n\t Dn(2) = ( 2 + r*(-3.0d0 +r*(9.00d0 +r*(-37.5d0\n *\t\t+r*196.875d0) ) ) )/(2*z)\n\tend if\n\n\tif( z .lt. 7 ) then\n\t z6 = z4*z2\n\t xg(3) = 2.5d0*xg(2) + z*z4\n\t Dn(3) = 0.5d0*(xg(3)-3*z2*xg(2)+3*z4*xg(1)-z6*xg(0))\n\telse\n\t Dn(3) = ( 6 + r*(-12.0d0 +r*(45.0d0 +r*(-225.0d0\n *\t\t+r*1378.125d0) ) ) )/(2*z)\n\tend if\n\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Gamma function math routine calculates\nC\nC\t gf06(n) = g(n,x) * int{y=x,z} [log(y) * exp(-y) * y**(2*n) dy]\nC\nC\tand\nC\nC\t gg06(n) = g(n,x) * int{y=x,z} [ exp(-y) * y**(2*n) dy ]\nC\t = g(n,x) * ( Gamma(2*n+1,x) - Gamma(2*n+1,z) )\nC\nC\tfor n=0,6, with g(n,x) = exp(x) * max(1,x)**(-2*n)\nC\nC ====================================================================\n\n\tsubroutine atm8_chap_gfg06( x, z, gf06, gg06 )\n\timplicit real*8 (a-h,o-z)\n\tparameter (gamma = 0.5772156649015328606d0)\n\tdimension gf06(0:6), gg06(0:6)\n\tdimension gh13x(13), gh13z(13), rgn(13), delta(13)\n\tcall atm8_chap_gh13( x, x, gh13x )\n\tcall atm8_chap_gh13( x, z, gh13z )\n\tif( x .le. 1 ) then\n\t rho = 1\n\telse\n\t rho = 1/x\n\tend if\n\n\tdelta(1) = 0\n\tdelta(2) = ( gh13x(1) - gh13z(1) ) * rho\n\trgn(1) = 1\n\trgn(2) = rho\n\tdo n=2,12\n\t delta(n+1) = rho*( n*delta(n) + gh13x(n) - gh13z(n) )\n\t rgn(n+1) = (n*rho)*rgn(n)\n\tend do\n\n\tif( x .gt. 0 ) then\n\t xE1_x = atm8_chap_zxE1(x)/x\n\t xlog = log(x)\n\tend if\n\tif( z .gt. 0 ) then\n\t xE1_z = exp(x-z)*atm8_chap_zxE1(z)/z\n\t zlog = log(z)\n\tend if\n\n\tdo k=0,6\n\t n = 2*k+1\n\t if( x .le. 0 ) then\n\t gf06(k) = -gamma*rgn(n) + delta(n)\n\t else\n\t gf06(k) = xlog*gh13x(n) + rgn(n)*xE1_x + delta(n)\n\t end if\n\t if( z .le. 0 ) then\n\t gf06(k) = gf06(k) + gamma*rgn(n)\n\t else\n\t gf06(k) = gf06(k) - (zlog*gh13z(n) + rgn(n)*xE1_z)\n\t end if\n\t gg06(k) = gh13x(n) - gh13z(n)\n\tend do\n\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Gamma function math routine calculates\nC\nC\t gg06(n) = g(n,x) * int{y=x,z} [ exp(-y) * y**(2*n) dy ]\nC\t = g(n,x) * ( Gamma(2*n+1,x) - Gamma(2*n+1,z) )\nC\nC\tfor n=0,6, with g(n,x) = exp(x) * max(1,x)**(-2*n)\nC\nC ====================================================================\n\n\tsubroutine atm8_chap_gg06( x, z, gg06 )\n\timplicit real*8 (a-h,o-z)\n\tdimension gg06(0:6), gh13x(13), gh13z(13)\n\tcall atm8_chap_gh13( x, x, gh13x )\n\tcall atm8_chap_gh13( x, z, gh13z )\n\tdo n=0,6\n\t gg06(n) = gh13x(2*n+1) - gh13z(2*n+1)\n\tend do\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Gamma function math routine calculates\nC\nC\t gh13(n) = f(n,x) * int{y=z,infinity} [exp(-y) * y**(n-1) dy]\nC\t = f(n,x) * Gamma(n,z)\nC\nC\tfor n=1,13, with f(n,x) = exp(x) * max(1,x)**(-n+1)\nC\nC ====================================================================\n\n\tsubroutine atm8_chap_gh13( x, z, gh13 )\n\timplicit real*8 (a-h,o-z)\n\tdimension gh13(13), Tab(12)\n\n\tif( z .le. 0 ) then\n\t gh13(1) = 1\n\t do n=1,12\n\t gh13(n+1) = n*gh13(n)\n\t end do\n\t return\n\tend if\n\n\tif( x .le. 1 ) then\n\t rho = 1\n\telse\n\t rho = 1/x\n\tend if\n\trhoz = rho * z\n\texz = exp(x-z)\n\tTab(12) = exp( (x-z) + 12*log(rhoz) )\n\tdo n=11,1,-1\n\t Tab(n) = Tab(n+1)/rhoz\n\tend do\n\tgh13(1) = exz\n\tdo n=1,12\n\t gh13(n+1) = rho*n*gh13(n) + Tab(n)\n\tend do\n\treturn\n\tend\n\nC ====================================================================\nC\nC\tThis Gamma function math subroutine calculates\nC\nC\t Qn(x) = x**n * exp(x) * Gamma(-n+0.5,x), n=0,8\nC\t = x**n * exp(x) * int{y=x,infinity} [exp(-y)*y**(-n-0.5)dy]\nC\nC\tFor x .lt. 2 we first calculate\nC\nC\t Q0(x) = sqrt(pi)*exp(x)*erfc(sqrt(x)) = exp(x)*Gamma(0.5,x)\nC\nC\tand use upward recursion. Else, we first calculate\nC\nC\t Q8(x) = x**8 * exp(x) * Gamma(-7.5,x)\nC\nC\tfollowing Press et al. [PFT86, pp162-63, GCF.FOR] and then\nC\trecur downward. Also see Abramowitz and Stegun [AS64, 6.5].\nC\nC ====================================================================\n\n\tsubroutine atm8_chap_gq85( x, qn )\n\timplicit real*8(a-h,o-z)\n\tparameter (rpi=1.7724538509055160273d0)\n\tparameter (itmax=100,eps=3.0d-9)\n\tdimension qn(0:8)\n\n\tif( x .le. 0 ) then\n\t qn(0) = rpi\n\t do i=1,8\n\t qn(i) = 0\n\t end do\n\t return\n\tend if\n\n\trx = sqrt(x)\n\n\tif( x .lt. 2 ) then\n\t qn(0) = rpi * atm8_chap_xerfc( rx )\n\t do n=1,8\n\t qn(n) = ( -rx*qn(n-1) + 1 ) * rx / ( n - 0.5d0 )\n\t end do\n\telse\n GOLD=0.0d0\n\t A0=1.0d0\n\t A1=x\n\t B0=0.0d0\n\t B1=1.0d0\n\t FAC=1.0d0\n\t DO 11 N=1,ITMAX\n\t AN= (N)\n\t ANA=AN + 7.5d0\n\t A0=(A1+A0*ANA)*FAC\n\t B0=(B1+B0*ANA)*FAC\n\t ANF=AN*FAC\n\t A1=x*A0+ANF*A1\n\t B1=x*B0+ANF*B1\n\t FAC=1./A1\n G=B1*FAC\n\t test = G*eps\n\t del = G - Gold\n\t if( test .lt. 0 ) test = - test\n\t if( (del .ge. -test) .and. (del .le. test) ) go to 12\n\t GOLD=G\n11 CONTINUE\n12\t qn(8) = G * rx\n\t do n=8,1,-1\n\t qn(n-1) = ( (-n+0.5d0)*qn(n)/rx + 1 ) / rx\n\t end do\n\tend if\n\n\treturn\n\tend\n", "meta": {"hexsha": "95de0b4bd2c7ceb31ae772f74625448cf2dccbf8", "size": 37325, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/so/chapman/chapman.for", "max_stars_repo_name": "htyeim/HTbin.jl", "max_stars_repo_head_hexsha": "03511086b1ca5c3287d123a267dd19411142f113", "max_stars_repo_licenses": ["MIT"], "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/so/chapman/chapman.for", "max_issues_repo_name": "htyeim/HTbin.jl", "max_issues_repo_head_hexsha": "03511086b1ca5c3287d123a267dd19411142f113", "max_issues_repo_licenses": ["MIT"], "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/so/chapman/chapman.for", "max_forks_repo_name": "htyeim/HTbin.jl", "max_forks_repo_head_hexsha": "03511086b1ca5c3287d123a267dd19411142f113", "max_forks_repo_licenses": ["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.8446676971, "max_line_length": 71, "alphanum_fraction": 0.5496048225, "num_tokens": 14218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.863391599428538, "lm_q1q2_score": 0.8091799272194566}} {"text": "MODULE fortranfft\ncontains\n\n SUBROUTINE generate_exp(N, exp_factors)\n ! Generates the exponential factors which are used in the subroutines\n ! bellow.\n !\n ! Inputs : N \n !\n ! Outputs : exp_factors - array of the form W[n] = exp(-2j*pi*n/N)\n\n implicit none\n\n integer, intent(in) :: N\n complex(8), dimension(0:N/2-1), intent(out) :: exp_factors\n\n real(8), parameter :: PI = 4*atan(1.0_8)\n complex(8), parameter :: Imag = (0.0_8, 1.0_8)\n\n integer :: i\n\n do i = 0, N/2-1\n exp_factors(i) = exp(-2*Imag*PI*i/N)\n end do\n\n END SUBROUTINE generate_exp\n\n SUBROUTINE dft(N,x,f)\n ! A direct implementation of the Discrete Fourier Transform.\n !\n ! Inputs : x - the array which we perform the DFT on.\n ! N - the number of elements in x.\n !\n ! Outputs : f - the transformed array.\n\n implicit none\n\n integer, intent(in) :: N\n complex(8), dimension(0:N-1), intent(in) :: x\n complex(8), dimension(0:N-1), intent(out) :: f\n\n real(8), parameter :: PI = 4*atan(1.0_8)\n complex(8), parameter :: Imag = (0.0_8, 1.0_8)\n\n complex(8) :: sum_exp = (0,0)\n integer :: i, j\n\n do i = 0, N-1\n do j = 0, N-1\n sum_exp = sum_exp + exp(-2*PI*Imag*i*j/N) * x(j)\n end do\n f(i) = sum_exp\n sum_exp = (0,0)\n end do\n\n END SUBROUTINE dft\n\n RECURSIVE SUBROUTINE fft(N,x,exp_factors,f)\n ! A Fast Fourier Transform using the Cooley-Tukey radix-2 algorithm.\n !\n ! Inputs : x - the array which we perform the DFT on.\n ! N - the number of elements in x.\n ! exp_factors - the array exponentials of the form exp(-2j*pi*n/N)\n !\n ! Outputs : f - the transformed array.\n\n implicit none\n\n integer, intent(in) :: N\n complex(8), dimension(0:N-1), intent(in) :: x\n complex(8), dimension(0:N/2-1), intent(in) :: exp_factors\n complex(8), dimension(0:N-1), intent(out) :: f\n\n complex(8), dimension(0:N/2-1) :: f_even, f_odd\n\n ! If input array has length 2 or less it returns the regular DFT.\n if (N .le. 2) then\n call dft(N,x,f)\n\n ! If the input array is divisible by 2, it calls itself recursively on both\n ! the even and odd elements and then adds them together.\n else if (mod(N,2) == 0) then\n call fft(N/2, x(1::2), (exp_factors(0:N/2-1))**2, f_odd)\n call fft(N/2, x(::2), (exp_factors(0:N/2-1))**2, f_even)\n\n f(0:N/2-1) = f_even(0:N/2-1) + f_odd(0:N/2-1) * exp_factors(0:N/2-1)\n f(N/2:) = f_even(0:N/2-1) - f_odd(0:N/2-1) * exp_factors(0:N/2-1)\n\n ! For robustness, even if the array is not furher divisible by 2, we return\n ! the regular DFT regardless of size.\n else\n call dft(N,x,f)\n end if\n\n END SUBROUTINE fft\n\n SUBROUTINE fft2(N,x,exp_factors,f)\n ! A 2D FFT based on the 1D case. Complexity is O(N^2 log N) as opposed to\n ! O(N^4) for the 2D DFT.\n !\n ! Inputs : x - the NxN array which we perform the DFT on.\n ! N - the length of each dimension of x.\n ! exp_factors - the array exponentials of the form exp(-2j*pi*n/N)\n !\n ! Outputs : f - the transformed array.\n\n implicit none\n\n integer, intent(in) :: N\n complex(8), dimension(0:N-1, 0:N-1), intent(in) :: x\n complex(8), dimension(0:N/2-1), intent(in) :: exp_factors\n complex(8), dimension(0:N-1, 0:N-1), intent(out) :: f\n\n integer :: i\n\n ! Creates the 2D array f, whose rows are FFTs of the rows of x.\n do i = 0, N-1\n call fft(N,x(i,:),exp_factors, f(i,:))\n end do\n\n ! Replaces each column in f with its fourier transform.\n do i = 0, N-1\n call fft(N,f(:,i),exp_factors, f(:,i))\n end do\n\n END SUBROUTINE fft2\n\n\nEND MODULE fortranfft\n", "meta": {"hexsha": "2bdf4f19953fe232a4163d7cc20d4c16a5a86fac", "size": 3673, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Module/fortranfft.f95", "max_stars_repo_name": "rusruskov/Fortran-FFT", "max_stars_repo_head_hexsha": "ebcd773d61bb06163b14a868b81986bc6a52fe11", "max_stars_repo_licenses": ["MIT"], "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/fortranfft.f95", "max_issues_repo_name": "rusruskov/Fortran-FFT", "max_issues_repo_head_hexsha": "ebcd773d61bb06163b14a868b81986bc6a52fe11", "max_issues_repo_licenses": ["MIT"], "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/fortranfft.f95", "max_forks_repo_name": "rusruskov/Fortran-FFT", "max_forks_repo_head_hexsha": "ebcd773d61bb06163b14a868b81986bc6a52fe11", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-08T07:48:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-08T07:48:42.000Z", "avg_line_length": 28.2538461538, "max_line_length": 79, "alphanum_fraction": 0.5937925402, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8090057592216311}} {"text": "program pg20\r\n implicit none\r\n ! Section: Specification\r\n integer :: mml,i,j,retinfo\r\n double precision, allocatable :: a(:,:)\r\n double precision, allocatable :: ata(:,:), meye(:,:)\r\n integer, allocatable :: ipiv(:)\r\n character(len=512) :: dfmt\r\n ! Section: Execution\r\n mml = 5\r\n retinfo = 0\r\n ! Format for I/O\r\n write(dfmt, '(a,i0,a)') '(',mml,'f7.2)'\r\n !\r\n allocate(a(mml,mml), ata(mml,mml), meye(mml,mml), ipiv(mml))\r\n ! 'meye' is an Identity matrix\r\n meye = 0.0\r\n do i = 1,mml\r\n meye(i,i) = 1.0\r\n end do\r\n ! 'a' is now assigned values\r\n do i = 1,mml\r\n do j = 1,mml\r\n a(i,j) = 10*i + j\r\n end do\r\n end do\r\n write(*,*) 'Input:'\r\n write(*,dfmt) transpose(a)\r\n !\r\n call dgetrf(mml,mml,a,mml,ipiv,retinfo)\r\n ! call getrf(a,ipiv,retinfo)\r\n !\r\n if (retinfo /= 0) then\r\n write(*,*) 'The matrix is singular: dgetrf returned ', retinfo\r\n else\r\n write(*,*) 'LU Result:'\r\n write(*,dfmt) transpose(a)\r\n write(*,*)\r\n write(*,*) 'Pivots:'\r\n write(*,*) ipiv\r\n write(*,*)\r\n write(*,*) 'Identity:'\r\n write(*,dfmt) transpose(meye)\r\n call dtrmm('L','U','N','N',mml,mml,1.0d0,a,mml,meye,mml)\r\n call dtrmm('L','L','N','U',mml,mml,1.0d0,a,mml,meye,mml)\r\n write(*,*)\r\n write(*,*) 'After trmm:'\r\n write(*,dfmt) transpose(meye)\r\n do i = mml,1,-1\r\n call s_rowexch(ipiv(i),i,meye)\r\n end do\r\n write(*,*)\r\n write(*,*) 'After reversing pivots:'\r\n write(*,dfmt) transpose(meye)\r\n end if\r\n deallocate(a, ata, meye, ipiv)\r\n contains\r\n subroutine s_rowexch(row_a,row_b,m)\r\n implicit none\r\n integer, intent(in) :: row_a, row_b\r\n double precision, intent(inout) :: m(:,:)\r\n double precision, allocatable :: tmprow(:)\r\n allocate(tmprow(size(m,2)))\r\n !\r\n tmprow = m(row_b,:)\r\n m(row_b,:) = m(row_a,:)\r\n m(row_a,:) = tmprow\r\n !\r\n deallocate(tmprow)\r\n end subroutine s_rowexch\r\nend program pg20\r\n", "meta": {"hexsha": "de9e345e0c312640e10ed5eb6bcfa34e10f3d03b", "size": 2165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gadi/src/020-lu-factor.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/020-lu-factor.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/020-lu-factor.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": 30.0694444444, "max_line_length": 71, "alphanum_fraction": 0.4933025404, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802529509909, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.8089947143576995}} {"text": "!Fortran uses the unit number to access the file with later read and write statements. Several files can be open at once, but each must have a different number. There is one thing to remember about numbering a file - you cannot use the number 6, as GNU Fortran reserves that number to refer to the screen.\nprogram read\n\timplicit none\n\tINTEGER :: options\n\tINTEGER :: i\n\tREAL :: a, b\n\tREAL :: addanswer, subtractanswer\n\tREAL :: multiplyanswer, divisionanswer\n\treal, dimension(100) :: p, q\n real :: pi\n \treal :: radius\n \treal :: height\n \treal :: area\n \treal :: volume\n\tpi = 3.1415927\n\t! character type string to clear a users screen\n\t!print *, achar(27)//\"[2J\"\n\t!\n\tprint *, \" _____ _ ___ ___ \"\n\tprint *, \"| __|___ ___| |_ ___ ___ ___ _____| . | _|\"\n\tprint *, \"| __| . | _| _| _| .'| |_____|_ |_ |\"\n\tprint *, \"|__| |___|_| |_| |_| |__,|_|_|_____|___|___|\" \n\tprint *, \"-------------------------------------------------|\"\n\tprint *, \"1 => calculate a basic equation |\"\n\tprint *, \"2 => Get the radius of a cylinder |\"\n\tprint *, \"-------------------------------------------------|\"\n\tprint *, \" Please enter a command below: \"\n\tread(*,*) options\n\tIF (options == 1) THEN\n\t\tprint *, ''\t \n\t\tprint *, '[ | ] Please input the first integer '\n\t\tread(*,*) a\n\t\tprint *, ''\n\t\tprint *, '[ | ] Please input the second integer '\n\t\tread(*,*) b\n\t\t!\n\t\taddanswer = a + b\n \t\tsubtractanswer = a - b\n \t\tmultiplyanswer = a * b\n \t\tdivisionanswer = a / b\n\t\t! \n\t\tprint *, \"_________________________________________________________|\"\n print *, \"|Results : Addition, Subtraction, Multiplication, divsion|\"\n \t print *, \"------------------------------------------------------------------------\"\n \t\twrite(*,*) a, \" + \", b, \" = \", addAnswer\n \t\twrite(*,*) a, \" - \", b, \" = \", subtractanswer\n \t\twrite(*,*) a, \" * \", b, \" = \", multiplyanswer\n \t\twrite(*,*) a, \" / \", b, \" = \", divisionanswer\n\t\topen(unit = 2, file = \"output.txt\")\n \t\t!the files unit is = to 2 so i would need to make the write unit the same as 2\n\t\tprint *, ''//achar(27)//'[31m '//achar(27)//'[0m'\n\t\twrite(2, *) a, \" + \", b, \" = \", addAnswer\n\t\twrite(2, *) a, \" - \", b, \" = \", subtractanswer\n\t\twrite(2, *) a, \" * \", b, \" = \", multiplyanswer\n \t write(2, *) a, \" / \", b, \" = \", divisionanswer\n\t\tprint *, \"------------------------------------------------------------------------\"\n\t\tclose(2)\n\t\tPRINT*, \"[ | ] Data written to a file |output.txt| [ | ] \"\n\tELSE IF (options == 2) THEN\n\t\tprint *, ''\n print *, '[ | ] Enter cylinder base radius:'\n read(*,*) radius\n\t\tprint *, ''\n print *, '[ | ] Enter cylinder height:'\n read(*,*) height\n area = pi * radius**2.0\n volume = area * height\n\t\tprint *, ''\n\t\tprint *, ''\n\t\tprint *, ''\n\t\tprint *, '_______________________________________'\n print *, '[ = ] Cylinder radius => ', radius\n\t print *, '[ = ] Cylinder height => ', height\n print *, '[ = ] Cylinder base area => ', area\n \t\tprint *, '[ = ] Cylinder volume => ', volume\t\n\tEND IF\nend program read\n", "meta": {"hexsha": "0978dbb7c3232db11ac1354d101d07c6a5cd8053", "size": 3245, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main5=txtinsert.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": "main5=txtinsert.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": "main5=txtinsert.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": 41.6025641026, "max_line_length": 305, "alphanum_fraction": 0.4825885978, "num_tokens": 852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8840392924390585, "lm_q1q2_score": 0.8088083888012951}} {"text": "!--------------------------------------------------------------------\n!\n!\n! PURPOSE\n!\n! This program solves nonlinear Klein-Gordon equation in 3 dimensions\n! u_{tt}-(u_{xx}+u_{yy}+u_{zz})+u=Es*|u|^2u\n! using a second order implicit-explicit time stepping scheme.\n!\n! The boundary conditions are u(x=-Lx*pi,y,z)=u(x=Lx*\\pi,y,z), \n! u(x,y=-Ly*pi,z)=u(x,y=Ly*pi,z),u(x,y,z=-Ly*pi)=u(x,y,z=Ly*pi),\n! The initial condition is u=0.5*exp(-x^2-y^2-z^2)*sin(10*x+12*y)\n!\n! .. Parameters ..\n! Nx = number of modes in x - power of 2 for FFT\n! Ny = number of modes in y - power of 2 for FFT\n! Nz = number of modes in z - power of 2 for FFT\n! Nt = number of timesteps to take\n! Tmax = maximum simulation time\n! plotgap = number of timesteps between plots\n! pi = 3.14159265358979323846264338327950288419716939937510d0\n! Lx = width of box in x direction\n! Ly = width of box in y direction\n! Lz = width of box in z direction\n! ES = +1 for focusing and -1 for defocusing\n! .. Scalars ..\n! i = loop counter in x direction\n! j = loop counter in y direction\n! k = loop counter in z direction\n! n = loop counter for timesteps direction \n! allocatestatus = error indicator during allocation\n! start = variable to record start time of program\n! finish = variable to record end time of program\n! count_rate = variable for clock count rate\n! dt = timestep\n! modescalereal = Number to scale after backward FFT \n! ierr = error code\n! plotnum = number of plot\n! myid = Process id\n! p_row = number of rows for domain decomposition\n! p_col = number of columns for domain decomposition\n! filesize = total filesize\n! disp = displacement to start writing data from\n! .. Arrays ..\n! unew = approximate solution\n! vnew = Fourier transform of approximate solution\n! u = approximate solution\n! v = Fourier transform of approximate solution\n! uold = approximate solution\n! vold = Fourier transform of approximate solution\n! nonlin = nonlinear term, u^3\n! nonlinhat = Fourier transform of nonlinear term, u^3\n! .. Vectors ..\n! kx = fourier frequencies in x direction\n! ky = fourier frequencies in y direction\n! kz = fourier frequencies in z direction\n! x = x locations\n! y = y locations\n! z = z locations\n! time = times at which save data\n! en = total energy \n! enstr = strain energy\n! enpot = potential energy\n! enkin = kinetic energy\n! name_config = array to store filename for data to be saved \n! fftfxyz = array to setup 2D Fourier transform\n! fftbxyz = array to setup 2D Fourier transform\n! .. Special Structures ..\n! decomp = contains information on domain decomposition\n! see http://www.2decomp.org/ for more information\n! REFERENCES\n!\n! ACKNOWLEDGEMENTS\n!\n! ACCURACY\n! \n! ERROR INDICATORS AND WARNINGS\n!\n! FURTHER COMMENTS\n! Check that the initial iterate is consistent with the \n! boundary conditions for the domain specified\n!--------------------------------------------------------------------\n! External routines required\n! getgrid.f90 -- Get initial grid of points\n! initialdata.f90 -- Get initial data\n! enercalc.f90 -- Subroutine to calculate the energy\n! savedata.f90 -- Save initial data\n! storeold.f90 -- Store old data\n! External libraries required\n! 2DECOMP&FFT -- Domain decomposition and Fast Fourier Library\n! (http://www.2decomp.org/index.html)\n! MPI library\n\nPROGRAM Kg\n use decomp_2d\n use decomp_2d_fft\n use decomp_2d_io\n !coprocessing:\n use KGadaptor_module\n\n implicit none\n INCLUDE 'mpif.h'\n ! Declare variables\n INTEGER(kind=4) :: Nx, Ny, Nz, Nt, plotgap \n REAL(kind=8), PARAMETER :: &\n pi=3.14159265358979323846264338327950288419716939937510d0\n REAL(kind=8) :: Lx,Ly,Lz,Es,dt,starttime,modescalereal \n COMPLEX(kind=8), DIMENSION(:), ALLOCATABLE :: kx,ky,kz \n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: x,y,z \n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: u,nonlin\n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: v,nonlinhat\n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: uold\n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: vold\n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: unew\n COMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: vnew\n REAL(kind=8), DIMENSION(:,:,:), ALLOCATABLE :: savearray\n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: time,enkin,enstr,enpot,en\n INTEGER(kind=4) :: ierr,i,j,k,n,allocatestatus,myid,numprocs\n INTEGER(kind=4) :: start, finish, count_rate, plotnum\n TYPE(DECOMP_INFO) :: decomp\n INTEGER(kind=MPI_OFFSET_KIND) :: filesize, disp\n INTEGER(kind=4) :: p_row=0, p_col=0 \n CHARACTER*100 :: name_config\n ! initialisation of 2DECOMP&FFT\n CALL MPI_INIT(ierr)\n CALL MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) \n\n CALL readinputfile(Nx,Ny,Nz,Nt,plotgap,Lx,Ly,Lz, &\n Es,DT,starttime,myid,ierr)\n ! do automatic domain decomposition\n CALL decomp_2d_init(Nx,Ny,Nz,p_row,p_col)\n ! get information about domain decomposition choosen\n CALL decomp_info_init(Nx,Ny,Nz,decomp)\n ! initialise FFT library\n CALL decomp_2d_fft_init\n ALLOCATE(kx(decomp%zst(1):decomp%zen(1)),&\n ky(decomp%zst(2):decomp%zen(2)),&\n kz(decomp%zst(3):decomp%zen(3)),&\n x(decomp%xst(1):decomp%xen(1)),&\n y(decomp%xst(2):decomp%xen(2)),&\n z(decomp%xst(3):decomp%xen(3)),&\n u(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n v(decomp%zst(1):decomp%zen(1),&\n decomp%zst(2):decomp%zen(2),&\n decomp%zst(3):decomp%zen(3)),&\n nonlin(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n nonlinhat(decomp%zst(1):decomp%zen(1),&\n decomp%zst(2):decomp%zen(2),&\n decomp%zst(3):decomp%zen(3)),&\n uold(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n vold(decomp%zst(1):decomp%zen(1),&\n decomp%zst(2):decomp%zen(2),&\n decomp%zst(3):decomp%zen(3)),&\n unew(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n vnew(decomp%zst(1):decomp%zen(1),&\n decomp%zst(2):decomp%zen(2),&\n decomp%zst(3):decomp%zen(3)),&\n savearray(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n time(1:1+Nt/plotgap),enkin(1:1+Nt/plotgap),&\n enstr(1:1+Nt/plotgap),enpot(1:1+Nt/plotgap),&\n en(1:1+Nt/plotgap),stat=allocatestatus) \n IF (allocatestatus .ne. 0) stop \n IF (myid.eq.0) THEN \n PRINT *,'allocated arrays'\n END IF\n ! setup fourier frequencies\n CALL getgrid(myid,Nx,Ny,Nz,Lx,Ly,Lz,pi,name_config,x,y,z,kx,ky,kz,decomp)\n IF (myid.eq.0) THEN \n PRINT *,'Setup grid and fourier frequencies'\n END IF\n CALL initialdata(Nx,Ny,Nz,x,y,z,u,uold,decomp)\n plotnum=1 \n name_config = 'data/u' \n savearray=REAL(u)\n! CALL savedata(Nx,Ny,Nz,plotnum,name_config,savearray,decomp)\n\n CALL decomp_2d_fft_3d(u,v,DECOMP_2D_FFT_FORWARD)\n CALL decomp_2d_fft_3d(uold,vold,DECOMP_2D_FFT_FORWARD)\n\n modescalereal=1.0d0/REAL(Nx,KIND(0d0))\n modescalereal=modescalereal/REAL(Ny,KIND(0d0))\n modescalereal=modescalereal/REAL(Nz,KIND(0d0))\n\n CALL enercalc(myid,Nx,Ny,Nz,dt,Es,modescalereal,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),&\n kx,ky,kz,nonlin,nonlinhat,&\n v,vold,u,uold,decomp)\n\n IF (myid.eq.0) THEN \n PRINT *,'Got initial data, starting timestepping'\n END IF\n time(plotnum)=0.0d0+starttime\n CALL system_clock(start,count_rate) \n\n !coprocessing:\n call coprocessorinitialize(\"pipeline.py\", 11)\n\n DO n=1,Nt \n DO k=decomp%xst(3),decomp%xen(3)\n DO j=decomp%xst(2),decomp%xen(2)\n DO i=decomp%xst(1),decomp%xen(1)\n nonlin(i,j,k)=(abs(u(i,j,k))*2)*u(i,j,k)\n END DO\n END DO\n END DO\n CALL decomp_2d_fft_3d(nonlin,nonlinhat,DECOMP_2D_FFT_FORWARD)\n DO k=decomp%zst(3),decomp%zen(3)\n DO j=decomp%zst(2),decomp%zen(2)\n DO i=decomp%zst(1),decomp%zen(1)\n vnew(i,j,k)=&\n ( 0.25*(kx(i)*kx(i) + ky(j)*ky(j)+ kz(k)*kz(k)-1.0d0)&\n *(2.0d0*v(i,j,k)+vold(i,j,k))&\n +(2.0d0*v(i,j,k)-vold(i,j,k))/(dt*dt)&\n +Es*nonlinhat(i,j,k) )&\n /(1/(dt*dt)-0.25*(kx(i)*kx(i)+ ky(j)*ky(j)+ kz(k)*kz(k)-1.0d0))\n END DO\n END DO\n END DO\n CALL decomp_2d_fft_3d(vnew,unew,DECOMP_2D_FFT_BACKWARD)\n ! normalize result\n DO k=decomp%xst(3),decomp%xen(3)\n DO j=decomp%xst(2),decomp%xen(2)\n DO i=decomp%xst(1),decomp%xen(1)\n unew(i,j,k)=unew(i,j,k)*modescalereal\n END DO\n END DO\n END DO\n IF (mod(n,plotgap)==0) THEN\n plotnum=plotnum+1\n time(plotnum)=n*dt+starttime\n IF (myid.eq.0) THEN\n PRINT *,'time',n*dt+starttime\n END IF\n CALL enercalc(myid,Nx,Ny,Nz,dt,Es,modescalereal,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),&\n kx,ky,kz,nonlin,nonlinhat,&\n vnew,v,unew,u,decomp)\n savearray=REAL(unew,kind(0d0))\n! CALL savedata(Nx,Ny,Nz,plotnum,name_config,savearray,decomp)\n END IF\n !coprocessing:\n call KGadaptor(Nx, Ny, Nz, decomp%xst(1), decomp%xen(1), &\n decomp%xst(2), decomp%xen(2), decomp%xst(3), decomp%xen(3), &\n n, n*dt+starttime, savearray) \n\n ! .. Update old values ..\n CALL storeold(Nx,Ny,Nz,unew,u,uold,vnew,v,vold,decomp)\n END DO\n !coprocessing:\n call coprocessorfinalize()\n\n CALL system_clock(finish,count_rate)\n IF (myid.eq.0) THEN\n PRINT *,'Finished time stepping'\n PRINT*,'Program took ',&\n REAL(finish-start,kind(0d0))/REAL(count_rate,kind(0d0)),&\n 'for Time stepping'\n CALL saveresults(Nt,plotgap,time,en,enstr,enkin,enpot) \n ! Save times at which output was made in text format\n PRINT *,'Saved data'\n END IF\n CALL decomp_2d_fft_finalize\n CALL decomp_2d_finalize\n\n DEALLOCATE(kx,ky,kz,x,y,z,u,v,nonlin,nonlinhat,savearray,&\n uold,vold,unew,vnew,time,enkin,enstr,enpot,en,&\n stat=allocatestatus) \n IF (allocatestatus .ne. 0) STOP \n IF (myid.eq.0) THEN\n PRINT *,'Deallocated arrays'\n PRINT *,'Program execution complete'\n END IF\n CALL MPI_FINALIZE(ierr)\n\nEND PROGRAM Kg\n", "meta": {"hexsha": "94b71e119c22530599cafd82ad7cfa952972acdc", "size": 11862, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "KleinGordon/Programs/KleinGordon3dMpiFFTParaView/KgSemiImp3d.f90", "max_stars_repo_name": "bcloutier/PSNM", "max_stars_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_stars_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-01-05T14:22:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T23:51:25.000Z", "max_issues_repo_path": "KleinGordon/Programs/KleinGordon3dMpiFFTParaView/KgSemiImp3d.f90", "max_issues_repo_name": "bcloutier/PSNM", "max_issues_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_issues_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-01T07:31:32.000Z", "max_forks_repo_path": "KleinGordon/Programs/KleinGordon3dMpiFFTParaView/KgSemiImp3d.f90", "max_forks_repo_name": "bcloutier/PSNM", "max_forks_repo_head_hexsha": "1cd03f87f93ca6cb1a3cfbe73e8bc6106f497ddf", "max_forks_repo_licenses": ["CC-BY-3.0", "BSD-2-Clause"], "max_forks_count": 34, "max_forks_repo_forks_event_min_datetime": "2015-01-05T14:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-09T06:55:01.000Z", "avg_line_length": 41.044982699, "max_line_length": 90, "alphanum_fraction": 0.5594334851, "num_tokens": 3612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047778, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8087748157553764}} {"text": "module mod_monolis_shape_util\n use mod_monolis_prm\n\ncontains\n\n subroutine monolis_get_inverse_matrix_2d(xj, inv, det, is_fail)\n implicit none\n real(kdouble) :: xj(2,2), inv(2,2), det, detinv\n logical, optional :: is_fail\n\n det = xj(1,1) * xj(2,2) &\n - xj(2,1) * xj(1,2)\n\n if(det < 0.0d0)then\n if(present(is_fail))then\n is_fail = .true.\n else\n stop \"determinant < 0.0\"\n endif\n endif\n\n detinv = 1.0d0/det\n inv(1,1) = xj(2,2)*detinv\n inv(1,2) = -xj(1,2)*detinv\n inv(2,1) = -xj(2,1)*detinv\n inv(2,2) = xj(1,1)*detinv\n end subroutine monolis_get_inverse_matrix_2d\n\n subroutine monolis_get_inverse_matrix_3d(xj, inv, det, is_fail)\n implicit none\n real(kdouble) :: xj(3,3), inv(3,3), det, detinv\n logical, optional :: is_fail\n\n if(present(is_fail)) is_fail = .false.\n\n det = xj(1,1) * xj(2,2) * xj(3,3) &\n + xj(2,1) * xj(3,2) * xj(1,3) &\n + xj(3,1) * xj(1,2) * xj(2,3) &\n - xj(3,1) * xj(2,2) * xj(1,3) &\n - xj(2,1) * xj(1,2) * xj(3,3) &\n - xj(1,1) * xj(3,2) * xj(2,3)\n\n if(det < 0.0d0)then\n if(present(is_fail))then\n is_fail = .true.\n else\n stop \"determinant < 0.0\"\n endif\n endif\n\n detinv = 1.0d0/det\n inv(1,1) = detinv * ( xj(2,2)*xj(3,3) - xj(3,2)*xj(2,3))\n inv(1,2) = detinv * (-xj(1,2)*xj(3,3) + xj(3,2)*xj(1,3))\n inv(1,3) = detinv * ( xj(1,2)*xj(2,3) - xj(2,2)*xj(1,3))\n inv(2,1) = detinv * (-xj(2,1)*xj(3,3) + xj(3,1)*xj(2,3))\n inv(2,2) = detinv * ( xj(1,1)*xj(3,3) - xj(3,1)*xj(1,3))\n inv(2,3) = detinv * (-xj(1,1)*xj(2,3) + xj(2,1)*xj(1,3))\n inv(3,1) = detinv * ( xj(2,1)*xj(3,2) - xj(3,1)*xj(2,2))\n inv(3,2) = detinv * (-xj(1,1)*xj(3,2) + xj(3,1)*xj(1,2))\n inv(3,3) = detinv * ( xj(1,1)*xj(2,2) - xj(2,1)*xj(1,2))\n end subroutine monolis_get_inverse_matrix_3d\n\nend module mod_monolis_shape_util\n", "meta": {"hexsha": "38f9782ab5c08416714dbb84aff8cd91dee971f9", "size": 1888, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shape/shape_util.f90", "max_stars_repo_name": "nqomorita/monolis", "max_stars_repo_head_hexsha": "55d746a480fd7b9639216be19e0a253e6137dfe9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-03-11T20:24:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:31:06.000Z", "max_issues_repo_path": "src/shape/shape_util.f90", "max_issues_repo_name": "nqomorita/monolis", "max_issues_repo_head_hexsha": "55d746a480fd7b9639216be19e0a253e6137dfe9", "max_issues_repo_licenses": ["MIT"], "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/shape_util.f90", "max_forks_repo_name": "nqomorita/monolis", "max_forks_repo_head_hexsha": "55d746a480fd7b9639216be19e0a253e6137dfe9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-01T09:34:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-01T09:34:26.000Z", "avg_line_length": 29.5, "max_line_length": 65, "alphanum_fraction": 0.531779661, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.8519527982093668, "lm_q1q2_score": 0.808432718749358}} {"text": "*dk volume_qud\n subroutine volume_qud(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,\n * volqud)\nC\nC\nC#######################################################################\nC\nC PURPOSE -\nC\nC THIS ROUTINE FINDS THE VOLUME OF A QUD-ELEMENT DEFINDED BY\nC 4 COORDINATE NODES. THE VOLUME OF THE QUD IS DETERMINED\nC BY SUBDIVIDING IT INTO 4 TRIANGULAR ELEMENTS\nC USING THE MIDPOINT\nC AND THEN SUMMING THE VOLUME OF THE TRIANGLES.\nC\nC compare volume_qud_alt_lg below\nC\nC ******************************************************************\nC\nC DEFINE THE STRUCTURE OF A GENERIC QUD.\nC\nC\nC 4- - - -3 Edge 1: 1 2\nC | | 2: 2 3\nC | | 3: 3 4\nC 1- - - -2 4: 4 1\nC\nC ******************************************************************\nC\nC INPUT ARGUMENTS -\nC\nC (x1,y1,z1),...,(x4,y4,z4) - THE COORDINATES OF THE QUD.\nC\nC OUTPUT ARGUMENTS -\nC\nC volqud - THE VOLUME OF THE QUD.\nC\nC CHANGE HISTORY -\nC\nC $Log: volume_qud.f,v $\nC Revision 2.00 2007/11/09 20:04:06 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.4 Tue Oct 19 15:13:20 1999 jtg\nCPVCS fixed form of inv3x3 call\nCPVCS \nCPVCS Rev 1.3 Tue Oct 19 13:16:54 1999 jtg\nCPVCS alternate way of caluculating volume using \"minimum area\nCPVCS point\" (instead of midpoint) added.\nCPVCS \nCPVCS Rev 1.2 Mon Apr 14 17:05:40 1997 pvcs\nCPVCS No change.\nCPVCS \nCPVCS Rev 1.1 Mon Nov 11 20:55:52 1996 het\nCPVCS Remove the absolute value for volume.\nCPVCS \nCPVCS Rev 1.0 Mon Jul 29 15:42:48 1996 dcg\nCPVCS Initial revision.\nC\nC\nC#######################################################################\nC\n implicit real*8 (a-h,o-z)\nC\nC#######################################################################\nC\nC\nC ..................................................................\nC FIND THE MEDIAN POINT FOR EACH OF THE SIX FACES AND THE HEX.\nC\n x1234=(x1+x2+x3+x4)/4.0d+00\n y1234=(y1+y2+y3+y4)/4.0d+00\n z1234=(z1+z2+z3+z4)/4.0d+00\n\n !local_debug=0\n !if (local_debug.gt.0) then\n ! write(*,'(a,3f12.8)') 'using mid ',x1234,y1234,z1234\n !endif\nC\nC\nC ..................................................................\nC FIND THE VOLUME OF THE 4-TRI QUD.\nC\n call volume_tri(x1234,y1234,z1234,\n * x1,y1,z1,\n * x2,y2,z2,\n * voltri1)\n call volume_tri(x1234,y1234,z1234,\n * x2,y2,z2,\n * x3,y3,z3,\n * voltri2)\n call volume_tri(x1234,y1234,z1234,\n * x3,y3,z3,\n * x4,y4,z4,\n * voltri3)\n call volume_tri(x1234,y1234,z1234,\n * x4,y4,z4,\n * x1,y1,z1,\n * voltri4)\nC\nC\nC ..................................................................\nC SUM THE 4 TRI VOLUMES TO THE VOLUME OF THE QUD.\nC\n volqud=voltri1+voltri2+voltri3+voltri4\nC\n return\n end\nC#######################################################################\nC=======================================================================\nC#######################################################################\n*dk volume_qud_alt\n subroutine volume_qud_alt_lg(x1,y1,z1,x2,y2,z2\n * ,x3,y3,z3,x4,y4,z4,volqud\n * ,x1234,y1234,z1234)\nC\nC\nC#######################################################################\nC\nC PURPOSE -\nC\nC THIS ROUTINE FINDS THE VOLUME OF A QUD-ELEMENT DEFINDED BY\nC 4 COORDINATE NODES. THE VOLUME OF THE QUD IS DETERMINED\nC BY SUBDIVIDING IT INTO 4 TRIANGULAR ELEMENTS\nC USING THE POINT WHICH MINIMIZES THE SUM OF THE AREAS\nC AND THEN SUMMING THE VOLUME OF THE TRIANGLES.\nC\nC structure and arguments same as above\nC except call also returns \"min-area-point\" (x1234,y1234,z1234)\nC\nC#######################################################################\nC\n implicit none\n real*8 x1,y1,z1,x2,y2,z2 ,x3,y3,z3,x4,y4,z4,volqud\n * ,x1234,y1234,z1234\n\n real*8 mat(3,3),vec(3),d(3,4),s(3,4),dd(4),ds(4),ddd\n * ,voltri\n integer i,j,local_debug,iflag\nC\nC#######################################################################\nC\nC ..................................................................\nC FIND THE POINT WHICH MINIMIZES THE SUM OF THE AREAS\nC\n\n d(1,1)=x2-x1\n d(2,1)=y2-y1\n d(3,1)=z2-z1\n d(1,2)=x3-x2\n d(2,2)=y3-y2\n d(3,2)=z3-z2\n d(1,3)=x4-x3\n d(2,3)=y4-y3\n d(3,3)=z4-z3\n d(1,4)=x1-x4\n d(2,4)=y1-y4\n d(3,4)=z1-z4\n\n s(1,1)=x2+x1\n s(2,1)=y2+y1\n s(3,1)=z2+z1\n s(1,2)=x3+x2\n s(2,2)=y3+y2\n s(3,2)=z3+z2\n s(1,3)=x4+x3\n s(2,3)=y4+y3\n s(3,3)=z4+z3\n s(1,4)=x1+x4\n s(2,4)=y1+y4\n s(3,4)=z1+z4\n\n ddd=0.0d+0\n do j=1,4\n dd(j)=0.0d+0\n ds(j)=0.0d+0\n do i=1,3\n dd(j)=dd(j)+d(i,j)*d(i,j)\n ds(j)=ds(j)+d(i,j)*s(i,j)\n enddo\n ddd=ddd+dd(j)\n enddo\n\n do i=1,3\n vec(i)=d(i,1)*ds(1)+d(i,2)*ds(2)+d(i,3)*ds(3)+d(i,4)*ds(4)\n & -s(i,1)*dd(1)-s(i,2)*dd(2)-s(i,3)*dd(3)-s(i,4)*dd(4)\n vec(i)=vec(i)*0.5d+00\n do j=1,3\n mat(i,j)=d(i,1)*d(j,1)+d(i,2)*d(j,2)\n & +d(i,3)*d(j,3)+d(i,4)*d(j,4)\n enddo\n mat(i,i)=mat(i,i)-ddd\n enddo\n\n call inv3x3(mat(1,1),mat(1,2),mat(1,3)\n & ,mat(2,1),mat(2,2),mat(2,3)\n & ,mat(3,1),mat(3,2),mat(3,3)\n & ,vec(1),vec(2),vec(3)\n & ,x1234,y1234,z1234 ,iflag)\n\n !local_debug=0\n !if (local_debug.gt.0) then\n ! write(*,'(a,3f12.8)') 'using alt ',x1234,y1234,z1234\n !endif\n\nC ..................................................................\nC NOW FIND THE VOLUME OF THE 4-TRI QUD.\nC\n call volume_tri(x1234,y1234,z1234,\n & x1,y1,z1,\n & x2,y2,z2,\n & volqud)\n call volume_tri(x1234,y1234,z1234,\n & x2,y2,z2,\n & x3,y3,z3,\n & voltri)\n volqud=volqud+voltri\n call volume_tri(x1234,y1234,z1234,\n & x3,y3,z3,\n & x4,y4,z4,\n & voltri)\n volqud=volqud+voltri\n call volume_tri(x1234,y1234,z1234,\n & x4,y4,z4,\n & x1,y1,z1,\n & voltri)\n volqud=volqud+voltri\nC\n return\n end\nC#######################################################################\n", "meta": {"hexsha": "73ae3e209adb557f64f6b7d3cd359da71bc4a9fd", "size": 6855, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/volume_qud.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/volume_qud.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/volume_qud.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": 29.4206008584, "max_line_length": 74, "alphanum_fraction": 0.4059810357, "num_tokens": 2305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.808346506990807}} {"text": " module fft_m\n use kind_m\n implicit none\n private\n public :: fft_window\n integer , parameter :: np2 = 9, nn = 2**np2, nn_2 = nn / 2 ! 2^9 = 512\n real(kd), parameter :: pi = 4 * atan(1.0_kd), pi2 = 2 * pi\n real(kd), parameter :: pi2_n = pi2 / nn\n integer, save :: indx(nn) \n integer, private :: i_\n complex(kd), parameter :: omega(0:*) = [(exp(cmplx(0.0_kd, pi2_n * i_, kind = kd)), i_ = 0, nn - 1)] \n real(kd) , parameter :: hann_window(*) = [(0.5_kd * (1.0_kd - cos(pi2_n * i_)) , i_ = 0, nn - 1)]\n contains\n subroutine fft_initialize()\n integer :: i, j2, k, n\n do i = 1, nn\n n = 0\n k = i - 1\n do j2 = np2 - 1, 0, -1\n n = n + mod(k, 2) * 2**j2\n k = k / 2\n end do\n indx(i) = n + 1 ! indx = 1..n\n end do\n end subroutine fft_initialize\n \n subroutine fft_window(x, y)\n real (kd), intent(in ) :: x(:)\n complex (kd), intent(out) :: y(:)\n logical :: qfirst = .true.\n if (qfirst) then\n qfirst = .false.\n call fft_initialize()\n end if\n y = hann_window * x / nn\n call fft2(y)\n end subroutine fft_window\n\n subroutine fft2(fft) ! fft_2^np2\n complex (kd), intent(in out) :: fft(:)\n complex (kd) :: tmp1, tmp2, c1\n integer :: i, j, k2, m1, m2, iphase, kn2\n fft = fft(indx)\n do k2 = 1, np2\n kn2 = 2**(k2 - 1)\n do i = 1, nn, 2* kn2\n do j = 1, kn2\n iphase = 2**(np2 - k2)*(j - 1)\n c1 = omega( mod(iphase, nn) )\n m1 = i + j - 1\n m2 = m1 + kn2\n tmp1 = fft(m1)\n tmp2 = c1 * fft(m2)\n fft(m1) = tmp1 + tmp2 ! 1 = x^2 ; x = 1 or -1\n fft(m2) = tmp1 - tmp2\n end do\n end do\n end do\n end subroutine fft2\n end module fft_m\n", "meta": {"hexsha": "750e1dd922b20cea419ab33eb293d78c15ecde19", "size": 2223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft_m.f90", "max_stars_repo_name": "cure-honey/uzura1_fpm", "max_stars_repo_head_hexsha": "35a6bb4bf442c66d9a44f3aafc0a5d94c7bcc880", "max_stars_repo_licenses": ["MIT"], "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/fft_m.f90", "max_issues_repo_name": "cure-honey/uzura1_fpm", "max_issues_repo_head_hexsha": "35a6bb4bf442c66d9a44f3aafc0a5d94c7bcc880", "max_issues_repo_licenses": ["MIT"], "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/fft_m.f90", "max_forks_repo_name": "cure-honey/uzura1_fpm", "max_forks_repo_head_hexsha": "35a6bb4bf442c66d9a44f3aafc0a5d94c7bcc880", "max_forks_repo_licenses": ["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.4426229508, "max_line_length": 109, "alphanum_fraction": 0.3882141251, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739076, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8083464944575389}} {"text": "PROGRAM F023\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, DIMENSION(10000) :: ABUNDANT_NUMBERS = 0\n\n INTEGER :: N = 1\n INTEGER :: COUNT_VAL = 1\n\n INTEGER :: I, J, J_MAX, K, COUNT_BY_2, PROPER_DIVISORS_SUM\n\n LOGICAL :: ABUNDANT_SUM_FOUND\n\n DO I = 2, 28123\n\n PROPER_DIVISORS_SUM = 0\n\n J_MAX = FLOOR(REAL(I) / 2.0)\n\n DO J = 1, J_MAX\n IF (MOD(I, J) == 0) PROPER_DIVISORS_SUM = PROPER_DIVISORS_SUM + J;\n END DO\n\n IF (PROPER_DIVISORS_SUM > I) THEN\n ABUNDANT_NUMBERS(COUNT_VAL) = I\n COUNT_VAL = COUNT_VAL + 1\n END IF\n\n COUNT_BY_2 = FLOOR(REAL(COUNT_VAL) / 2.0)\n\n ABUNDANT_SUM_FOUND = .FALSE.\n\n DO J = 1, COUNT_BY_2\n\n K = J\n\n DO WHILE ((ABUNDANT_NUMBERS(J) + ABUNDANT_NUMBERS(K)) < I)\n K = K + 1\n END DO\n\n IF ((ABUNDANT_NUMBERS(J) + ABUNDANT_NUMBERS(K)) == I) THEN\n ABUNDANT_SUM_FOUND = .TRUE.\n EXIT\n END IF\n\n END DO\n\n IF (.NOT. ABUNDANT_SUM_FOUND) N = N + I\n\n END DO\n\n PRINT ('(I0)'), N\n\nEND PROGRAM F023\n", "meta": {"hexsha": "a3a11443cfc34223be8714b4ecc9320614c69d0f", "size": 1168, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/023/023.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/023/023.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/023/023.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.4912280702, "max_line_length": 78, "alphanum_fraction": 0.5299657534, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8080748501183606}} {"text": "C++********************************************************************\nC Set of routines:\nC JLP_FOURIER\nC\nC JLP\nC Version 11-07-91\nC--*******************************************************************\nC JLP_FOURIER\nC Computes the Fourier Transform of a real image (full of zeroes...) \nC\nC Zero frequency is in RE(1,1), and IM(1,1)\nC\nC Input:\nC IMAGE: Input image\nC\nC Output:\nC RE,IM: Real and imaginary part \nC\nC RE(KX,KY) = Sum on IX,IY of IMAGE(IX,IY)*COS(2*PI*(IX*(KX-1)/NX+IY*(KY-1)/NY))\nC IM(KX,KY) = Sum on IX,IY of IMAGE(IX,IY)*SIN(2*PI*(IX*(KX-1)/NX+IY*(KY-1)/NY))\nC\nC Tests: Big improvement in accuracy \nC when X0,X1,X0,Y1,PI,ANGLE,MYCOS, and MYSIN are real*8...\nC and when DCOS and DSIN are used.\nC*******************************************************************\n\tSUBROUTINE JLP_FOURIER(IMAGE,RE,IM,NX,NY,IDIM,ISIGN)\n\tPARAMETER (IDIM1=512, SMALLER_VALUE=1.E-12)\n\tREAL IMAGE(IDIM,*),RE(IDIM,*),IM(IDIM,*)\n\tREAL*8 X0,Y0,X1,Y1,SIGN\n\tREAL*8 PI,ANGLE\n\tINTEGER NX,NY,ISIGN\n\tREAL*8 MYCOS(IDIM1),MYSIN(IDIM1)\n\t\n\tPI=3.14159265358979323846\n\tX0=2.*PI/FLOAT(NX)\n\tY0=2.*PI/FLOAT(NY)\n\tSIGN=FLOAT(ISIGN)\n\nC Resetting arrays to zero:\n\tDO KY=1,NY\n\t DO KX=1,NX\n\t RE(KX,KY)=0.\n\t IM(KX,KY)=0.\n\t END DO\n\tEND DO\n\n IF(NX.EQ.NY)THEN\nC When NX=NY, we have:\nC RE(KX,KY) = Sum on IX,IY of IMAGE(IX,IY)*COS((2*PI/NX)*(IX*(KX-1)+IY*(KY-1)))\nC IM(KX,KY) = Sum on IX,IY of IMAGE(IX,IY)*SIN((2*PI/NX)*(IX*(KX-1)+IY*(KY-1)))\nC\nC Cosinus and sinus:\nC MYCOS(I) = COS(2*PI*(I-1)/NX)\n DO I=1,NX\n\t ANGLE=X0*FLOAT(I-1)\n\t MYCOS(I)=DCOS(ANGLE)\n\t MYSIN(I)=DSIN(ANGLE)\n END DO\n\nC Fourier Transform with pre-computed cosinus and sinus :\n\tDO IY=1,NY\n\t DO IX=1,NX\n\t IF(ABS(IMAGE(IX,IY)).GT.SMALLER_VALUE)THEN\n\t DO KY=1,NY\n\t DO KX=1,NX\n I=(IX-1)*(KX-1)+(IY-1)*(KY-1)\n I=MOD(I,NX)+1\n RE(KX,KY)=RE(KX,KY)+IMAGE(IX,IY)*MYCOS(I)\n IM(KX,KY)=IM(KX,KY)+IMAGE(IX,IY)*MYSIN(I)\n\t END DO\n\t END DO\n\t ENDIF\n\t END DO\n\tEND DO\n\n ELSE\n\nC Fourier Transform without pre-computed cosinus and sinus:\n\tDO IY=1,NY\n\t Y1=Y0*FLOAT(IY-1)\n\t DO IX=1,NX\n\t X1=X0*FLOAT(IX-1)\n\t IF(ABS(IMAGE(IX,IY)).GT.SMALLER_VALUE)THEN\n\t DO KY=1,NY\n\t DO KX=1,NX\n\t ANGLE=X1*FLOAT(KX-1)+Y1*FLOAT(KY-1)\n RE(KX,KY)=RE(KX,KY)+IMAGE(IX,IY)*DCOS(ANGLE)\n IM(KX,KY)=IM(KX,KY)+IMAGE(IX,IY)*DSIN(ANGLE)\n\t END DO\n\t END DO\n\t ENDIF\n\t END DO\n\tEND DO\n\n ENDIF\n\n\tRETURN\n\tEND\n", "meta": {"hexsha": "1f01ede12095956422e4d5bbd93adee5b56971ee", "size": 2526, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlp_numeric/fft_num/jlp_fourier.for", "max_stars_repo_name": "jlprieur/jlplib", "max_stars_repo_head_hexsha": "6073d7a7eb76d916662b1f8a4eb54f345cf7c772", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlp_numeric/fft_num/jlp_fourier.for", "max_issues_repo_name": "jlprieur/jlplib", "max_issues_repo_head_hexsha": "6073d7a7eb76d916662b1f8a4eb54f345cf7c772", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlp_numeric/fft_num/jlp_fourier.for", "max_forks_repo_name": "jlprieur/jlplib", "max_forks_repo_head_hexsha": "6073d7a7eb76d916662b1f8a4eb54f345cf7c772", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-09T00:20:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-09T00:20:49.000Z", "avg_line_length": 25.5151515152, "max_line_length": 80, "alphanum_fraction": 0.5387965162, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.8078420486020608}} {"text": "module eratosthenes_sieve_mod\n use,intrinsic :: iso_fortran_env\n use vector_mod\n implicit none\n public\n integer(int32),private,parameter:: prec=int32\n type:: factor_pair\n integer(prec):: val\n integer(prec):: cnt\n end type\n integer(prec), allocatable:: sieve(:)\n type(vector_int32):: primes\n\ncontains\n subroutine make_sieve(n)\n ! 初期化 O(n)\n ! 1. エラトステネスの篩の表を作る。\n ! 2. 素数集合Vectorを作る。\n integer(prec),intent(in):: n\n integer(prec):: i,j\n \n allocate(sieve(n),source=0_prec)\n do i=2,n\n if (sieve(i)/=0) cycle\n call primes%push_back(i)\n sieve(i) = i\n do j= i*i, n, i\n if (sieve(j)==0) sieve(j) = i\n end do\n end do\n end subroutine\n\n\n function prime_factor_vec(x) result(ret)\n ! xの素因数をvectorで返す。ex) x=24 -> vector[2,2,2,3]\n ! NEED => vector構造, sieve(初期化)\n integer(prec),value:: x\n type(vector_int32):: ret\n\n ! if(x==1) call ret%push_back(1_prec)\n do while(x/=1)\n call ret%push_back(sieve(x))\n x=x / sieve(x)\n end do\n end function\n\n\n function factor(x) result(ret)\n ! xの素因数の集合とそのカウントをfactor_pairの配列で返す。\n ! ex) x=720 (= 2^4 * 3^2 *5^1)\n ! i | 1 2 3 (ただの添え字)\n ! val | 2 3 5 (素因数の重複なし集合)\n ! cnt | 4 2 1 (素因数の計数)\n !\n ! NEED -> vector構造, sieve(初期化), factor_pair構造\n ! i番目の素因数の値    -> ret(i)%val\n ! i番目の素因数のカウント -> ret(i)%num\n ! 素因数の重複なし集合 -> ret(:)%val\n\n integer(prec),intent(in):: x\n integer(prec):: i,j\n type(vector_int32):: fv\n type(factor_pair),allocatable:: tmp(:), ret(:)\n fv = prime_factor_vec(x)\n\n if (fv%l == 0) then\n allocate(ret(0))\n return\n end if\n\n allocate(tmp(fv%l), source=factor_pair(0,0))\n tmp(1)%val = fv%array(1); tmp(1)%cnt = 1\n j=1\n do i=2,fv%l\n if (fv%array(i) == fv%array(i-1)) then\n tmp(j)%cnt = tmp(j)%cnt + 1\n else\n j=j+1\n tmp(j)%val = fv%array(i)\n tmp(j)%cnt = 1\n end if\n end do\n ret = tmp(1:j)\n end function\n\n\n function is_prime(x) result(ret)\n ! xが素数なら.true. そうでないなら.false.を返す\n ! 1は素数ではないので, 1 => .false.となる。\n ! NEED -> sieve(初期化)\n integer(prec),intent(in):: x\n logical:: ret\n\n ret = sieve(x) == x\n end function\nend module", "meta": {"hexsha": "c5d079343c9f11ee61bf9bb26639237e3636405b", "size": 2530, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eratosthenes_sieve.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/eratosthenes_sieve.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/eratosthenes_sieve.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.3541666667, "max_line_length": 54, "alphanum_fraction": 0.5007905138, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109728022221, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.8078219337165338}} {"text": "program ch1301\n ! Quadratic Roots\n implicit none\n\n real :: a, b, c\n real :: term, a2\n real :: root1, root2\n\n print *, 'give the coefficients a, b and c'\n read *, a, b, c\n term = b*b - 4.*a*c\n a2 = a*2.\n if (term<0.) then\n print *, 'roots are complex'\n elseif (term>0.) then\n term = sqrt(term)\n root1 = (-b+term)/a2\n root2 = (-b-term)/a2\n print *, 'roots are ', root1, ' and ', root2\n else\n root1 = -b/a2\n print *, 'roots are equal, at ', root1\n end if\nend program\n", "meta": {"hexsha": "8bea7bf69a6841cfacb4804793846a37ffd3d6dd", "size": 552, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch13/ch1301.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": "ch13/ch1301.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": "ch13/ch1301.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.08, "max_line_length": 52, "alphanum_fraction": 0.5072463768, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.952574129515172, "lm_q2_score": 0.8479677660619634, "lm_q1q2_score": 0.8077521566133998}} {"text": "program multi_dimensional_bruteforce_mc\n\n !Author : Anantha Rao\n ! Reg no : 20181044\n ! 6D (x1,x2,x3,x4,x5,x6) Integral\n implicit none\n integer:: n,i,j\n real*8 :: x(6), y, func, int_mc, var, sigma, p(6)\n ! p : Dummy argument for random number generator (6 values)\n real*8 :: length, volume\n\n length=5.0d0 ! use one side of each dimension (0,5)\n volume=(2.0d0*length)**6 ! volume of 6D space\n\n open(unit=1, file=\"20181044_multi_brute_mc.dat\")\n n=1\n\n ! Initiate variables\n\n\nprint *,\"Welcome to this program.& \n& This program solves mutidimensional integral using Monte-Carlo rule\"\n\n 7 int_mc=0.0d0\n var=0.0d0\n sigma=0.0d0\n write(*,10) n\n 10 format(\"Computig for n=\",i10)\n\n do i=1,n\n call random_number(p)\n do j=1,6\n x(j) = -length + 2.0d0*length*p(j)\n end do\n int_mc=int_mc+func(x)\n sigma=sigma+func(x)*func(x)\n end do\n\n int_mc = int_mc/real(n)\n sigma=sigma/real(n)\n var=sigma-int_mc*int_mc\n\n int_mc = volume*int_mc\n sigma=volume*sqrt(var/real(n))\n\n write(1,*) n, \"\", int_mc, \"\", sigma\n\n ! begin automation\n n=n*10\n if (n .lt. 1000000000 ) goto 7\n print*,\"Done! Output stored in file 20181044_multi_brute_mc.dat\"\n ! end automation\n\n\nend program\n\n\nreal*8 function func(x)\n implicit none\n real*8::x(6), xx, yy, xy\n real*8::a,b\n a=1.0d0\n b=0.5d0\n\n xx= x(1)*x(1) + x(2)*x(2) + x(3)*x(3)\n yy= x(4)*x(4) + x(5)*x(5) + x(6)*x(6)\n xy= (x(1)-x(4))**2 + (x(2)-x(5))**2 + (x(3)-x(6))**2\n func=exp(-a*xx - a*yy - b*xy)\n\nend function\n", "meta": {"hexsha": "d03437e7517a2a9f1248527adde43f77f6aecde9", "size": 1664, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn02_solns/Assgn02_p3_mc_bruteforce.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_p3_mc_bruteforce.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_p3_mc_bruteforce.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": 23.4366197183, "max_line_length": 70, "alphanum_fraction": 0.5546875, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.8077208959098694}} {"text": "c \n module mod_user_routines \nc\n contains\nc\n subroutine buildVoigtCMat(lameShear, lameLambda, cOut, cInvOut)\n implicit none\n double precision, intent(in) :: lameShear, lameLambda\n double precision, intent(inout) :: cOut(6,6), cInvOut(6,6)\nc Builds the elastic stiffness matrix into, cOut, as well as its \nc inverse, cInvOut. NOTE, the matrix assumes ENGINEERING strains to \nc stresses! A factor of 2 has been added since engineering \nc shear strains are not used. In other words, Voigt notation is \nc adopted.\n integer :: m, n, np\n double precision :: young, poiss\n np = 3\n young = (lameShear*(3.D0*lameLambda+2.D0*lameShear))/\n & (lameLambda+lameShear)\n poiss = lameLambda/(2.D0*(lameLambda+lameShear))\nc lameShear = young/(2.D0*(1.D0+poiss))\nc lameLambda = young*poiss/((1.D0+poiss)*(1.D0-2.D0*poiss))\n\n cOut = 0.D0\n do m=1,np\n do n=1,np\n if (m .ne. n) cOut(m,n) = lameLambda\n end do\n cOut(m,m) = 2.D0*lameShear + lameLambda\n cOut(m+3,m+3) = lameShear !NOTE: Lack of 2 here\n end do\n\n cInvOut = 0.D0\n do m=1,np\n do n=1,np\n if (m .ne. n) cInvOut(m,n) = -poiss/young\n end do\n cInvOut(m,m) = 1.D0/young\n cInvOut(m+3,m+3) = (2.D0/young)*(1.D0 + poiss) !NOTE: The 2\n end do\n end subroutine buildVoigtCMat\nc \n subroutine buildMandelCMat(lameShear, lameLambda, cOut, cInvOut)\n implicit none\n double precision, intent(in) :: lameShear, lameLambda\n double precision, intent(inout) :: cOut(6,6), cInvOut(6,6)\nc Builds the elastic stiffness matrix into, cOut, as well as its \nc inverse, cInvOut. NOTE, the matrix assumes TENSOR strains to \nc stresses! A factor of 2 has been added since engineering \nc shear strains are not used. In other words, Mandel notation is \nc adopted.\n integer :: m, n, np\n double precision :: young, poiss\n np = 3\n young = (lameShear*(3.D0*lameLambda+2.D0*lameShear))/\n & (lameLambda+lameShear)\n poiss = lameLambda/(2.D0*(lameLambda+lameShear))\nc lameShear = young/(2.D0*(1.D0+poiss))\nc lameLambda = young*poiss/((1.D0+poiss)*(1.D0-2.D0*poiss))\n\n cOut = 0.D0\n do m=1,np\n do n=1,np\n if (m .ne. n) cOut(m,n) = lameLambda\n end do\n cOut(m,m) = 2.D0*lameShear + lameLambda\n cOut(m+3,m+3) = 2.D0*lameShear !NOTE: There's a 2 here\n end do\n\n cInvOut = 0.D0\n do m=1,np\n do n=1,np\n if (m .ne. n) cInvOut(m,n) = -poiss/young\n end do\n cInvOut(m,m) = 1.D0/young\n cInvOut(m+3,m+3) = (1.D0/young)*(1.D0 + poiss) !NOTE: Lack of 2 \n end do\n end subroutine buildMandelCMat\n\n subroutine buildP4Mat(P4Out)\n implicit none\n double precision, intent(inout) :: P4Out(6,6)\nc Builds the rank-4 deviatoric projection tensor. The output is in\nc P4Out(1:6,1:6). This tensor, when multiplied by a Voigt or Mandel\nc vector representing a rank-2 tensor, say vec(1:6), results in an\nc Voigt or Mandel vector, respectively that corresponds to the\nc deviatoric components of the original rank-2 tensor.\n integer :: m, n, np\n\n np = 3\n P4Out = 0.D0\n do m=1,np\n do n=1,np\n if (m .ne. n) P4Out(m,n) = -1.D0/3.D0\n end do\n P4Out(m,m) = 2.D0/3.D0\n P4Out(m+3,m+3) = 1.D0\n end do\n end subroutine buildP4Mat\nc \n subroutine mandel2Matrix(manVecIn, matOut)\n implicit none\nc Takes a Mandel vector and converts it back into a 3 X 3 matrix\nc with the SQRT(2) factor taken out of the deviatoric terms. Warp3D\nc follows the same conventions as Abaqus Standard. More \nc specifically, the order of stress/strain components are:\nc 1 - xx\nc 2 - yy\nc 3 - zz\nc 4 - xy\nc 5 - xz\nc 6 - yz\nc Shear strains are taken to be TENSOR COMPONENTS! The user may\nc need to divide the shear strains by a factor of 2.0 before using\nc this routine if the shear strains were originally given as \nc engineering components. \n double precision, parameter :: SQRT2=1.414213562373095048801688724\n double precision, intent(in) :: manVecIn(6)\n double precision, intent(inout) :: matOut(3,3)\nc \n matOut(1,1) = manVecIn(1)\n matOut(2,2) = manVecIn(2)\n matOut(3,3) = manVecIn(3)\n matOut(1,2) = manVecIn(4)/SQRT2\n matOut(2,1) = manVecIn(4)/SQRT2\n matOut(1,3) = manVecIn(5)/SQRT2 ! Abaqus Standard stores\n matOut(3,1) = manVecIn(5)/SQRT2 ! the shear components in a \n matOut(2,3) = manVecIn(6)/SQRT2 ! different order than Abaqus\n matOut(3,2) = manVecIn(6)/SQRT2 ! Explicit. WATCH OUT\n end subroutine mandel2Matrix\nc\n subroutine matrix2Mandel(matIn, manVecOut)\n implicit none\nc Takes a 3 X 3 symmetric matrix and converts into a Mandel vector\nc by adding a SQRT(2) to the shear terms. Warp3D follows the same\nc conventions as Abaqus Standard. More specifically, the order of\nc stress/strain components are:\nc 1 - xx\nc 2 - yy\nc 3 - zz\nc 4 - xy\nc 5 - xz\nc 6 - yz\nc Shear strains are taken to be TENSOR COMPONENTS! The user may\nc need to divide the shear strains by a factor of 2.0 before using\nc this routine if the shear strains were originally given as \nc engineering components. \n double precision, parameter :: SQRT2=1.414213562373095048801688724\n double precision, intent(in) :: matIn(3,3)\n double precision, intent(inout) :: manVecOut(6)\nc \n manVecOut(1) = matIn(1,1)\n manVecOut(2) = matIn(2,2)\n manVecOut(3) = matIn(3,3) ! Abaqus Standard stores\n manVecOut(4) = matIn(1,2)*SQRT2 ! the shear components in a \n manVecOut(5) = matIn(1,3)*SQRT2 ! different order than Abaqus\n manVecOut(6) = matIn(2,3)*SQRT2 ! Explicit. WATCH OUT\n end subroutine matrix2Mandel\nc\n subroutine mandelMat2VoigtMat(matIn, matOut)\n implicit none\nc Takes a matrix in Mandel notation and converts it to Voigt (for \nc what is usually done with the kinematic terms). \n double precision, parameter :: SQRT2=1.414213562373095048801688724\n double precision, intent(in) :: matIn(6,6) \n double precision, intent(inout) :: matOut(6,6)\n integer :: m, n\n double precision :: matTemp(6,6)\nc \n matOut = 0.D0\n matTemp = 0.D0\n do n=1,3\n do m=1,3\n matTemp(m,n) = matIn(m,n)\n end do\n end do\n\n do n=4,6 \n do m=1,3\n matTemp(m,n) = matIn(m,n)/SQRT2\n end do\n end do\n\n do n=1,3 \n do m=4,6\n matTemp(m,n) = matIn(m,n)/SQRT2\n end do\n end do\n\n do n=4,6\n do m=4,6\n matTemp(m,n) = matIn(m,n)/2.D0\n end do\n end do\n\n matOut(:,:) = matTemp(1:6,1:6)\n end subroutine mandelMat2VoigtMat\nc\n subroutine voigtMat2MandelMat(matIn, matOut)\n implicit none\nc Takes a matrix in Voigt notation (for the kinematic terms) and \nc converts it to Mandel \n double precision, parameter :: SQRT2=1.414213562373095048801688724\n double precision, intent(in) :: matIn(6,6)\n double precision, intent(inout) :: matOut(6,6)\n double precision :: matTemp(6,6)\n integer :: m, n\n\n matOut = 0.D0\n matTemp = 0.D0\n do n=1,3\n do m=1,3\n matTemp(m,n) = matIn(m,n)\n end do\n end do\n\n do n=4,6 \n do m=1,3\n matTemp(m,n) = matIn(m,n)*SQRT2\n end do\n end do\n\n do n=1,3 \n do m=4,6\n matTemp(m,n) = matIn(m,n)*SQRT2\n end do\n end do\n\n do n=4,6\n do m=4,6\n matTemp(m,n) = matIn(m,n)*2.D0\n end do\n end do\n\n matOut(:,:) = matTemp(1:6,1:6)\n end subroutine voigtMat2MandelMat\nc\n subroutine mandelVec2VoigtVec(vecIn, vecOut, useTwo)\n implicit none\nc Takes a vector in Mandel notation and converts it to a Voigt \nc vector. When useTwo < 1, then it is assumed that the Voigt vector\nc is stored in tensor components. Hence, only a factor of sqrt(2) \nc is needed on the shear terms. If useTwo >= 1, then a factor of two \nc will be included on the shear terms to accomodate for engineering \nc (kinematic) components. \n double precision, parameter :: SQRT2=1.414213562373095048801688724\n integer, intent(in) :: useTwo\n double precision, intent(in) :: vecIn(6)\n double precision, intent(inout) :: vecOut(6)\nc\n vecOut = vecIn\n if (useTwo .lt. 1) then\n vecOut(4) = vecOut(4)/SQRT2\n vecOut(5) = vecOut(5)/SQRT2\n vecOut(6) = vecOut(6)/SQRT2\n else\n vecOut(4) = (2.0*vecOut(4))/SQRT2\n vecOut(5) = (2.0*vecOut(5))/SQRT2\n vecOut(6) = (2.0*vecOut(6))/SQRT2\n end if\n end subroutine mandelVec2VoigtVec\nc \n subroutine voigtVec2MandelVec(vecIn, vecOut, useTwo)\n implicit none\nc Takes a vector in Voigt notation and converts it to a Mandel \nc vector. When useTwo < 1, then it is assumed that the Voigt vector\nc is stored in tensor components. Hence, only a factor of sqrt(2) \nc is needed on the shear terms. If useTwo >= 1, then a factor of two \nc will be included on the shear terms to accomodate for engineering \nc (kinematic) components.\n double precision, parameter :: SQRT2=1.414213562373095048801688724\n integer, intent(in) :: useTwo\n double precision, intent(in) :: vecIn(6)\n double precision, intent(inout) :: vecOut(6)\nc\n vecOut = vecIn\n if (useTwo .lt. 1) then\n vecOut(4) = vecOut(4)*SQRT2\n vecOut(5) = vecOut(5)*SQRT2\n vecOut(6) = vecOut(6)*SQRT2\n else\n vecOut(4) = (vecOut(4)/2.0)*SQRT2\n vecOut(5) = (vecOut(5)/2.0)*SQRT2\n vecOut(6) = (vecOut(6)/2.0)*SQRT2\n end if\n end subroutine voigtVec2MandelVec\nc \n subroutine lubksb(a, np, indx, b)\n implicit none\n integer, intent(in) :: np, indx(np)\n double precision, intent(in) :: a(np,np)\n double precision, intent(inout) :: b(np)\nc Solves the set of np linear equations A · X = B. Here a is input, \nc not as the matrix A but rather as its LU decomposition, determined\nc by the routine ludcmp. indx is input as the permutation vector \nc returned by ludcmp. b(1:n) is input as the right-hand side vector \nc B, and returns with the solution vector X. a, n, np, and indx are \nc not modified by this routine and can be left in place for \nc successive calls with different right-hand sides b. This routine\nc takes into account the possibility that b will begin with many \nc zero elements, so it is efficient for use in matrix inversion.\nc\n integer :: i, ii, j, ll, n\n double precision :: summ\nc \n n = np\nc When ii is set to a positive value, it will become the index\nc of the first nonvanishing element of b. We now do the forward\nc substitution while also unscrambling the permutation as we go\n ii = 0 \n do i=1,n \n ll = indx(i) \n summ = b(ll)\n b(ll) = b(i)\n if (ii .ne. 0) then\n do j=ii,i-1\n summ = summ - a(i,j)*b(j)\n end do\n else if (summ .ne. 0.) then\n ii = i ! A nonzero element is encountered, so from now on \n endif ! we will have to do the sums in the loop above. \n b(i) = summ\n end do\nc\n do i=n,1,-1 ! Now do the backsubstitution\n summ = b(i)\n do j=i+1,n\n summ = summ - a(i,j)*b(j)\n end do\n b(i) = summ/a(i,i) ! Store a component of the solution vector X\n end do\n end subroutine lubksb\nc \n subroutine ludcmp(a, np, indx, d, singFlag)\n implicit none\n integer, intent(in) :: np \n integer, intent(inout) :: indx(np), singFlag\n double precision, intent(inout) :: a(np,np), d \nc \nc Largest expected n, and a small number. \n integer, parameter :: NMAX = 500\n double precision, parameter :: TINY = 1.0e-20\nc \nc Given a matrix a(1:np,1:np), with physical dimension np by np, \nc this routine replaces it by the LU decomposition of a rowwise \nc permutation of itself. a and n are input. a is output, arranged as \nc in equation (2.3.14) above; indx(1:n) is an output vector that \nc records the row permutation effected by the partial pivoting; d is\nc output as ±1 depending on whether the number of row interchanges \nc was even or odd, respectively. This routine is used in combination\nc with lubksb to solve linear equations or invert a matrix. See\nc Numerical Recipes in FORTRAN 77 for more details on the algorithms\n\n integer :: i, imax, j, k, n\n double precision :: aamax, dum, summ, vv(NMAX) \nc vv stores the implicit scaling of each row.\nc\n n = np\n d = 1. ! No row interchanges yet.\n singFlag = 0 ! Set to 1 if singular\n do i=1,n ! Loop over rows to get the implicit scaling information\n aamax = 0.\n do j=1,n\n if (abs(a(i,j)) .gt. aamax) aamax = abs(a(i,j))\n end do\nc\n if (aamax .eq. 0.) then ! No nonzero largest element.\n !write (59,*) 'singular matrix in ludcmp' \n singFlag = 1\n return ! Exit subroutine and delete element\n !read (*,*)\n endif\n vv(i) = 1./aamax ! Save scaling\n end do\nc\n do j=1,n ! This is the loop over columns in Crout's method\n do i=1,j-1\n summ=a(i,j)\n do k=1,i-1\n summ = summ - a(i,k)*a(k,j)\n end do\n a(i,j) = summ\n end do\nc\n aamax = 0. ! Initialize for the search for largest pivot element\n do i=j,n\n summ = a(i,j)\n do k=1,j-1\n summ = summ - a(i,k)*a(k,j)\n end do\n a(i,j) = summ\n dum = vv(i)*abs(summ) ! Figure of merit for the pivot.\n if (dum .ge. aamax) then ! Is it better than the best so far?\n imax = i\n aamax = dum\n endif\n end do\nc \n if (j .ne. imax) then ! Do we need to interchange rows?\n do k=1,n ! Yes, do so...\n dum = a(imax,k)\n a(imax,k) = a(j,k)\n a(j,k) = dum\n end do\n d = -d ! ...and change the parity of d.\n vv(imax) = vv(j) ! Also interchange the scale factor.\n endif\n indx(j) = imax\n if (a(j,j) .eq. 0.) a(j,j) = TINY\nc If the pivot element is zero, the matrix is singular (at least \nc to the precision of the algorithm). For some applications on \nc singular matrices, it is desirable to substitute TINY for zero.\n if (j .ne. n) then ! Now, finally, divide by the pivot element\n dum = 1./a(j,j)\n do i=j+1,n\n a(i,j) = a(i,j)*dum\n end do\n endif\n end do ! Go back for the next column in the reduction.\n end subroutine ludcmp\nc\n subroutine calcinv(aMat, np, singFlag, aInv, aLU)\n implicit none\n integer, intent(in) :: np\n\n integer, intent(inout) :: singFlag\n double precision, intent(in) :: aMat(np,np)\n double precision, intent(inout), optional :: aLU(np,np)\n double precision, intent(inout) :: aInv(np,np)\nc Take the inverse of aMat by solving a linear system equal to the \nc identity matrix. The inverse is calculated using the LU-\nc decomposition method, which uses ludcmp(...). The resultant LU-\nc decomposed matrix is outputted in aLU. Amat is of size\nc np by np, and the inverse is returned in aInv. If aMat is \nc singular, and thus no inverse exists, singFlag will be equal to\nc 1; implying that if singFlag == 0, the inverse was a success.\n integer :: i, m\n integer :: indx(np)\n double precision :: d, aLU_cp(np,np)\n\n aInv = 0.\n aLU_cp = aMat\n singFlag = 0.\n m = np\n\n call ludcmp(aLU_cp, m, indx, d, singFlag)\n if (present(aLU)) then\n aLU = aLU_cp\n end if\n if (singFlag .eq. 1) then\n return\n end if\n\n call eyeMat(aInv, m)\n do i=1,m\n call lubksb(aLU_cp, m, indx, aInv(1,i))\n end do\n end subroutine calcinv\nc\n subroutine luinv(aLU, np, indx, aInv)\n implicit none\n integer, intent(in) :: np, indx(np) \n double precision, intent(in) :: aLU(np,np)\n double precision, intent(inout) :: aInv(np,np) \nc Calculates the inverse of aLU and outputs it in aInv. aLU must\nc already be decomposed into an LU-matrix; use ludcmp(...) to do so.\nc indx is an array of integers also outputted by ludcmp(...) that is\nc required here. The size of aLU is expected to np by np, and it is \nc assumed that aLU is invertible (not singular). \n integer :: i, m\n double precision :: aLU_cp(np,np)\n m = np\n\n aLU_cp = aLU\n call eyeMat(aInv, m)\n do i=1,m\n call lubksb(aLU_cp, m, indx, aInv(1,i))\n end do\n end subroutine luinv \nc \n subroutine ludet(aLU, np, d, aDet)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: aLU(np,np), d\n double precision, intent(inout) :: aDet\nc Works with the output of ludcmp(a, np, indx, d) where matrix \nc a(1:np) gets destroyed and replaced with a row-permutation of the \nc LU-decomposition of matrix a(1:np), denoted as input here, \nc aLU(1:np). Then, d (+1 or -1) is also calculated based on if the\nc number of row permutations are even or odd. This algorithm \nc attempts to locally scale the diagonals of aLU while calculating\nc the determinant in order to prevent an overflow. The resultant \nc determinant is stored into aDet.\nc\n integer :: i, m\n double precision :: rho, K, u(np), uMag, nn\nc\n m = np\n uMag = 0.\n do i=1,m ! Collect the diagonal components of aLU\n u(i) = aLU(i,i)\n end do\n call vecmag(u, m, uMag)\nc\n rho = 1.\n do i=1,m\n rho = rho*(u(i)/uMag)\n end do\n rho = d*rho\nc\n nn = np\n K = 0.\n do i=1,m\n K = K + log(uMag)\n end do\n K = exp((1./nn)*K)\nc\n aDet = rho*(K**np)\nc\nc Original, simpler method, but could cause overflow\nc m = np\nc aDet = d\nc do i=1,m\nc aDet = aDet*aLU(i,i)\nc end do\n end subroutine ludet \nc\n subroutine calcdet(Amat, np, Adet)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np)\n double precision, intent(inout) :: Adet\nc This is a quicker method of calculating the determinant of\nc either 1) a scaler value (np = 1); 2) a 2D matrix (np = 2);\nc or 3) a 3D matrix (np = 3). Otherwise, the determinant will be\nc calculated from an scaled LU-decomposition method. The \nc resultant determinant is stored in Adet.\nc\n integer :: i, m, failFlag, indxVec(np)\n double precision :: d, Amat_cp(np,np)\n m = np\n Adet = 0.\nc\n if (np .eq. 1) then\n Adet = Amat(1,1)\n elseif (np .eq. 2) then\n Adet = Amat(1,1)*Amat(2,2) - Amat(1,2)*Amat(2,1)\n elseif (np .eq. 3) then\n Adet = -Amat(1,3)*Amat(2,2)*Amat(3,1) +\n 1 Amat(1,2)*Amat(2,3)*Amat(3,1) +\n 2 Amat(1,3)*Amat(2,1)*Amat(3,2) -\n 3 Amat(1,1)*Amat(2,3)*Amat(3,2) -\n 4 Amat(1,2)*Amat(2,1)*Amat(3,3) +\n 5 Amat(1,1)*Amat(2,2)*Amat(3,3)\n else\n Amat_cp = Amat ! Make a copy\n call ludcmp(Amat_cp, np, indxVec, d, failFlag)\n call ludet(Amat_cp, np, d, Adet)\n endif\n end subroutine calcdet\nc\n subroutine getInvar(Amat, np, InvarVec)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np)\n double precision, intent(inout) :: InvarVec(3)\nc Calculates the 3 invariants of matrix Amat(1:np,1:np), and stores\nc them into InvarVec(1:3); InvarVec(1) = I1, InvarVec(2) = I2, and\nc InvarVec(3) = I3.\nc\n integer :: i, j, m\n double precision :: I1, I2, summ, I3, Amattr(np,np)\nc\n m = np\n I1 = 0.\n I2 = 0.\n I3 = 0.\nc\n do i=1,m ! I1 = trace[Amat]\n I1 = I1 + Amat(i,i)\n end do\nc\n call matrixtrnps(Amat, m, m, Amattr)\n call matdbldotmat(Amat, Amattr, m, summ)\n I2 = 0.5*(I1*I1 - summ)\nc\n call calcdet(Amat, np, I3)\nc\n InvarVec(1) = I1\n InvarVec(2) = I2\n InvarVec(3) = I3\n end subroutine getInvar\nc\n subroutine eyeMat(IMat, np)\n implicit none\nc Function eye(np) creates an np by np identity matrix into\nc IMat(1:np, 1:np), which gets destroyed in the process.\n integer, intent(in) :: np\n double precision, intent(inout) :: IMat(np,np)\n integer i, m\nc \n IMat = 0.D0\n m = np\n do i=1,m\n IMat(i,i) = 1.D0\n end do\n end subroutine eyeMat \nc\n subroutine vecdotvec(a, b, np, c)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: a(np), b(np)\n double precision, intent(inout) :: c\nc The inner dot product between vector a(1:np) and b(1:np), and \nc stores it into c.\nc integer :: i, m\nc m = np\n c = 0.\nc\nc do i=1,m\nc c = c + a(i)*b(i)\nc end do\nc\n c = dot_product(a,b)\n end subroutine vecdotvec\nc\n subroutine vecoutervec(a, b, np, c)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: a(np), b(np)\n double precision, intent(inout) :: c(np,np)\nc Two vectors, a(1:np) and b(1:np), are multiplied using the outer\nc product in order to produce a matrix, c(1:np, 1:np).\n integer :: i, j, m\n c = 0.D0\n m = np\n do j=1,m\n do i=1,m\n c(i,j) = a(i)*b(j)\n end do\n end do\n end subroutine vecoutervec\nc\n subroutine vecmag(bvec, np, bmag)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: bvec(np)\n double precision, intent(inout) :: bmag\nc Calculates the vector magnitude of bvec(1:np) and stores it\nc into bmag\nc integer :: i, m\nc m = np\n bmag = 0.\n\nc do i=1,m\nc bmag = bmag + bvec(i)*bvec(i)\nc end do\nc bmag = sqrt(bmag)\nc\n bmag = norm2(bvec)\n end subroutine vecmag \nc\n subroutine matFrobeniusnorm(Amat, np, L2Out)\n implicit none\nc Calculate the Frobenius norm of matrix Amat, and output in L2Out \n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np)\n double precision, intent(inout) :: L2Out\nc \n integer :: i, j, m\n double precision :: summ\nc \n L2Out = 0.D0\n summ = 0.D0\n m = np\n do i=1,m\n do j=1,m\n summ = summ + Amat(j,i)**2\n end do\n end do\nc \n L2Out = sqrt(summ)\n end subroutine matFrobeniusnorm\nc\n subroutine matdotvec(Amat, bvec, np, cvec)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np), bvec(np)\n double precision, intent(inout) :: cvec(np)\nc Calculates A [dot] b = c, or index notation, c_i = A_ij * b_j\nc integer :: i, j, m\nc\nc m = np\n cvec = 0.\nc do j=1,m\nc do i=1,m\nc cvec(i) = cvec(i) + Amat(i,j)*bvec(j)\nc end do\nc end do\nc\n cvec = MATMUL(Amat, bvec)\n end subroutine matdotvec\nc\n subroutine vecdotmat(Amat, bvec, np, cvec)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np), bvec(np)\n double precision, intent(inout) :: cvec(np)\nc Calculates b [dot] A = c, or index notation, c_j = A_ij * b_i\nc integer :: i, j, m\nc m = np\n\n cvec = 0.\nc do j=1,m\nc do i=1,m\nc cvec(j) = cvec(j) + Amat(i,j)*bvec(i)\nc end do\nc end do\n cvec = MATMUL(bvec, Amat)\n end subroutine vecdotmat\nc \n subroutine matdotmat(Amat, Bmat, np, Cmat)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np), Bmat(np,np)\n double precision, intent(inout) :: Cmat(np,np)\nc Calculates the inner product between two square matrices,\nc Amat and Bmat. The resultant matrix is, Cmat(1:np,1:np).\nc In index notation, C_ij = A_ik * B_kj, where it is implied \nc that there is a sum on k.\nc\nc integer :: i, j, k, m\nc m = np\n Cmat = 0.D0\nc \nc do j=1,m\nc do k=1,m\nc do i=1,m\nc Cmat(i,j) = Cmat(i,j) + Amat(i,k)*Bmat(k,j) \nc end do\nc end do\nc end do\nc\n Cmat = matmul(Amat, Bmat) \n end subroutine matdotmat\nc\n subroutine matdbldotmat(Amat, Bmat, np, c)\n implicit none\n integer, intent(in) :: np\n double precision, intent(in) :: Amat(np,np), Bmat(np,np)\n double precision, intent(inout) :: c\nc Calculates the double-dot product between two square matrices,\nc Amat and Bmat. The resultant scalar is, c. In index notation, \nc c = A_ij * B_ij, where it is implied that there is a sum on both\nc i and j. Note that no transposes are taken.\nc\n integer :: i, j, m\n m = np\n c = 0.D0\nc \n do j=1,m\n do i=1,m\n c = c + Amat(i,j)*Bmat(i,j)\n end do\n end do\n end subroutine matdbldotmat \nc\n subroutine matrixtrnps(Amat, rp, cp, Amattr)\n implicit none\n integer, intent(in) :: rp, cp\n double precision, intent(in) :: Amat(rp,cp)\n double precision, intent(inout) :: Amattr(cp,rp)\nc Transposes matrix Amat(1:rp,1:cp) and places it into \nc Amattr(1:cp,1:rp)... i.e., Amattr_ij = Amat_ji\nc \nc integer :: i, j, m, n\nc\n Amattr = 0.D0\nc m = rp\nc n = cp\nc do i=1,m\nc do j=1,n\nc Amattr(j,i) = Amat(i,j)\nc end do \nc end do\n Amattr = transpose(Amat)\n end subroutine matrixtrnps\nc\n subroutine calcPrinVals(Amat, eigsOut)\n implicit none\n double precision, intent(in) :: Amat(3,3)\n double precision, intent(inout) :: eigsOut(3)\nc Calculate the principal values of a 3D symmetric stress or \nc strain tensor. Amat is the input tensor, assumed to be 3 by 3.\nc The principal values (i.e., eigenvalues) are calculated \nc manually from the cubic equation based on the invariants. The \nc three eigenvalues are outputted in eigsOut in descending order.\n integer :: i, j\n double precision, parameter :: PI=3.1415926535897932384626433832\n double precision :: Qc, Rc, I1, I2, I3, RoverQ, theta,\n & e1, e2, e3, tempA \n double precision :: invarVec(3)\nc\n eigsOut = 0. \n do i=1,3\n do j=1,3\nc Check to ensure symmetry\n if (Amat(i,j) .ne. Amat(j,i)) return\n end do\n end do\nc\n call getInvar(Amat, 3, invarVec)\n I1 = invarVec(1)\n I2 = invarVec(2)\n I3 = invarVec(3)\nc\n Qc = (3.0*I2 - I1**2)/9.0\n Rc = (2.0*I1**3 - 9.0*I1*I2 + 27.0*I3)/54.0\n RoverQ = Rc/(sqrt(-Qc**3))\n theta = acos(RoverQ)\nc\n e1 = 2.0*sqrt(-Qc)*cos(theta/3.0) + I1/3.0\n e2 = 2.0*sqrt(-Qc)*cos((theta + 2.0*PI)/3.0) + I1/3.0\n e3 = 2.0*sqrt(-Qc)*cos((theta + 4.0*PI)/3.0) + I1/3.0\n eigsOut(1) = e1\n eigsOut(2) = e2\n eigsOut(3) = e3\nc\n do i=2,3\n tempA = eigsOut(i)\n j = i - 1\n do while (j .ge. 1)\n if (eigsOut(j) .ge. tempA) exit\n eigsOut(j+1) = eigsOut(j)\n j = j - 1\n end do\n eigsOut(j+1) = tempA\n end do\nc\n end subroutine calcPrinVals\nc\n subroutine tred2(a, np, d, e)\n integer, intent(in) :: np\n double precision, intent(inout) :: a(np,np), d(np), e(np)\nc Householder reduction of a real, symmetric np by np matrix a. On\nc output, a is replaced by the orthogonal matrix Q effecting the\nc transformation. d returns the diagonal elements of the tridiagonal\nc matrix, and e the off-diagonal elements, with e(1) = 0. This \nc function assumes the user wishes to calculate the eigenvalues and\nc eigenvectors.\n integer :: i, j, k, l, n\n double precision :: f, g, h, hh, scale\nc\n n = np\n do i=n,2,-1\n l = i - 1\n h = 0.\n scale=0.\n if (l .gt. 1) then \n do k=1,l\n scale = scale + abs(a(i,k))\n end do\n if (scale .eq. 0.) then\n e(i) = a(i,l)\n else\n do k=1,l\n a(i,k) = a(i,k)/scale\n h = h + a(i,k)**2\n end do\n f = a(i,l)\n g = -sign(sqrt(h),f)\n e(i) = scale*g\n h = h - f*g\n a(i,l) = f - g\n f = 0.\n do j=1,l\n a(j,i) = a(i,j)/h\n g = 0.\n do k=1,j\n g = g + a(j,k)*a(i,k)\n end do\n do k=j+1,l\n g = g + a(k,j)*a(i,k)\n end do\n e(j) = g/h\n f = f + e(j)*a(i,j)\n end do\n hh=f/(h + h)\n do j=1,l \n f = a(i,j)\n g = e(j) - hh*f\n e(j) = g\n do k=1,j\n a(j,k) = a(j,k) - f*e(k) - g*a(i,k)\n end do\n end do\n end if\n else\n e(i) = a(i,l)\n end if\n d(i) = h\n end do\n d(1)=0.\n e(1)=0.\n do i=1,n \n l = i - 1\n if (d(i) .ne. 0.) then\n do j=1,l\n g = 0.\n do k=1,l\n g = g + a(i,k)*a(k,j)\n end do\n do k=1,l\n a(k,j) = a(k,j) - g*a(k,i)\n end do\n end do\n endif\n d(i) = a(i,i)\n a(i,i) = 1. \n do j = 1,l \n a(i,j) = 0.\n a(j,i) = 0.\n end do\n end do\n end subroutine tred2\nc \n double precision function pythag(a, b)\n double precision, intent(in) :: a, b\nc finds dsqrt(a**2+b**2) without overflow or destructive underflow\n double precision :: p, r, s, t, u\n p = dmax1(dabs(a),dabs(b))\n if (p .eq. 0.0d0) go to 20\n r = (dmin1(dabs(a),dabs(b))/p)**2\n 10 continue\n t = 4.0d0 + r\n if (t .eq. 4.0d0) go to 20\n s = r/t\n u = 1.0d0 + 2.0d0*s\n p = u*p\n r = (s/u)**2 * r\n go to 10\n 20 pythag = p\n return\n end \nc\n subroutine tqli(d, e, np, z)\n integer, intent(in) :: np\n double precision, intent(inout) :: d(np), e(np), z(np,np)\nc QL algorithm with implicit shifts, to determine the eigenvalues\nc and eigenvectors of a REAL, SYMMETRIC, TRIDIAGONAL matrix. This\nc function works with the output of tred2(...). d is a vector of \nc length np. On input, its first np elements of the tridiagonal\nc matrix. On output, it returns the eigenvalues. The vector e inputs\nc the sub-diagonal elements of the tridiagonal matrix, with e(1)\nc arbitrary. On output, e is destroyed. This function assumes the \nc user wishes to calculate the eigenvalues and eigenvectors. The\nc tridiagonal output matrix from tred2(...), called Q, is expected\nc as input for z(np,np). As output, z returns the eigenvectors in \nc each column. That is, the kth column of z returns the normalized\nc eigenvector corresponding to d(k).\n integer :: i, iter, k, l, m, n\n double precision :: b, c, dd, f, g, p, r, s\n n = np\n do i=2,n\n e(i-1)=e(i)\n end do\n e(n)=0.\n do l=1,n\n iter = 0\n 1 do m = l,n-1\n dd = abs(d(m)) + abs(d(m+1))\n if (abs(e(m)) + dd .eq. dd) go to 2\n end do\n m = n\n 2 if (m .ne. l) then\n if (iter .eq. 30) then\nc pause 'too many iterations in tqli' \n end if \n iter = iter + 1\n g = (d(l+1) - d(l)) / (2.*e(l))\n r = pythag(g, 1.D0)\n g = d(m) - d(l) + e(l)/(g + sign(r,g))\n s = 1.\n c = 1.\n p = 0.\n do i=m-1,l,-1\n f = s*e(i)\n b = c*e(i)\n r = pythag(f, g)\n e(i+1) = r\n if (r .eq. 0.) then\n d(i+1) = d(i+1)-p\n e(m) = 0.\n go to 1\n end if\n s = f/r\n c = g/r\n g = d(i+1) - p\n r = (d(i) - g)*s + 2.*c*b\n p = s*r\n d(i+1) = g + p\n g=c*r - b\n do k=1,n\n f = z(k,i+1)\n z(k,i+1) = s*z(k,i) + c*f\n z(k,i) = c*z(k,i) - s*f\n end do\n end do\n d(l) = d(l) - p\n e(l) = g\n e(m) = 0.\n go to 1\n end if\n end do\n end subroutine tqli\nc\n subroutine eigSys(aMat, np, eigVals, eigVecs)\n integer, intent(in) :: np\n double precision, intent(in) :: aMat(np,np)\n double precision, intent(inout) :: eigVals(np), eigVecs(np,np)\nc Calculates the eigenvalues and normalized eigenvectors of matrix\nc aMat(np,np), which must be a real, symmetric matrix. The \nc eigenvalues are returned in eigVals(np) in descending order. The\nc corresponding eigenvectors are returned in the columns of eigVecs, \nc such that the kth column of eigVecs returns the normalized\nc eigenvector corresponding to eigVals(k). This function acts as the\nc driver function for calling tred2(...) and tqli(...). Note, that\nc transpose(eigVecs) * aMat * eigVecs will diagonlize aMat into \nc its eigenvalues.\n integer i, j, k, n\n double precision :: offDiag(np), p\nc \n n = np\n eigVals = 0.\n eigVecs = aMat\nc \n call tred2(eigVecs, n, eigVals, offDiag)\n call tqli(eigVals, offDiag, n, eigVecs)\nc\nc Sort eigenvalues and corresponding eigenvectors\n do i=1,n-1\n k = i\n p = eigVals(i)\n do j=i+1,n\n if (eigVals(j) .ge. p) then\n k = j\n p = eigVals(j)\n end if\n end do\n if (k .ne. i) then\n eigVals(k) = eigVals(i)\n eigVals(i) = p\n do j=1,n\n p = eigVecs(j,i)\n eigVecs(j,i) = eigVecs(j,k)\n eigVecs(j,k) = p\n end do\n end if\n end do\n\n end subroutine eigSys \nc \n end module mod_user_routines ", "meta": {"hexsha": "374c7051743a28c531bf0be188140ddf232024b8", "size": 34711, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "nmoser_linear_algebra.f", "max_stars_repo_name": "NM0ser/Lightweight-Linear-Algebra-Library-FORTRAN", "max_stars_repo_head_hexsha": "ac3e65b0dc73ad0eaeb9547c4dbe3f414b04005f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-07T22:02:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-07T22:02:37.000Z", "max_issues_repo_path": "nmoser_linear_algebra.f", "max_issues_repo_name": "NM0ser/Lightweight-Linear-Algebra-Library-FORTRAN", "max_issues_repo_head_hexsha": "ac3e65b0dc73ad0eaeb9547c4dbe3f414b04005f", "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": "nmoser_linear_algebra.f", "max_forks_repo_name": "NM0ser/Lightweight-Linear-Algebra-Library-FORTRAN", "max_forks_repo_head_hexsha": "ac3e65b0dc73ad0eaeb9547c4dbe3f414b04005f", "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.6538099718, "max_line_length": 159, "alphanum_fraction": 0.5513525972, "num_tokens": 11120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.945801274759925, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.8076317667592607}} {"text": "ELEMENTAL FUNCTION func_normal_PDF(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 PDF ...\n ans = EXP(-(tmp ** 2)) / (stddev * SQRT(2.0e0_REAL64 * const_pi))\nEND FUNCTION func_normal_PDF\n", "meta": {"hexsha": "ef5605d7ebd55eb98952e630592ae5e55d80ee77", "size": 892, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_normal_PDF.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_PDF.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_PDF.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.7826086957, "max_line_length": 89, "alphanum_fraction": 0.4596412556, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.8076268073903156}} {"text": "module bsplines\n\nuse types, only: dp\nuse lapack, only: dgesv, dgbsv\nuse utils, only: stop_error\nimplicit none\nprivate\npublic bspline, bspline_der, bspline_der2\n\ncontains\n\npure recursive function bspline(t, i, k, r) result(B)\n! Returns values of a B-spline.\n! There are set of `n` B-splines of order `k`. The mesh is composed of `n+k`\n! knots, stored in the t(:) array.\nreal(dp), intent(in) :: t(:) ! {t_i}, i = 1, 2, ..., n+k\ninteger, intent(in) :: i ! i = 1..n ?\ninteger, intent(in) :: k ! Order of the spline k = 1, 2, 3, ...\nreal(dp), intent(in) :: r(:) ! points to evaluate the spline at\nreal(dp) :: B(size(r))\nif (k == 1) then\n if ((t(size(t)) - t(i+1)) < tiny(1._dp) .and. &\n (t(i+1) - t(i)) > tiny(1._dp)) then\n ! If this is the last non-zero knot span, include the right end point,\n ! to ensure that the last basis function goes to 1.\n where (t(i) <= r .and. r <= t(i+1))\n B = 1\n else where\n B = 0\n end where\n else\n ! Otherwise exclude the right end point\n where (t(i) <= r .and. r < t(i+1))\n B = 1\n else where\n B = 0\n end where\n end if\nelse\n B = 0\n if (t(i+k-1)-t(i) > tiny(1._dp)) then\n B = B + (r-t(i)) / (t(i+k-1)-t(i)) * bspline(t, i, k-1, r)\n end if\n if (t(i+k)-t(i+1) > tiny(1._dp)) then\n B = B + (t(i+k)-r) / (t(i+k)-t(i+1)) * bspline(t, i+1, k-1, r)\n end if\nend if\nend function\n\npure function bspline_der(t, i, k, r) result(B)\n! Returns values of a derivative of a B-spline.\n! There are set of `n` B-splines of order `k`. The mesh is composed of `n+k`\n! knots, stored in the t(:) array.\nreal(dp), intent(in) :: t(:) ! {t_i}, i = 1, 2, ..., n+k\ninteger, intent(in) :: i ! i = 1..n ?\ninteger, intent(in) :: k ! Order of the spline k = 1, 2, 3, ...\nreal(dp), intent(in) :: r(:) ! points to evaluate the spline at\nreal(dp) :: B(size(r))\nif (k == 1) then\n B = 0\nelse\n B = 0\n if (t(i+k-1)-t(i) > tiny(1._dp)) then\n B = B + (k-1) / (t(i+k-1)-t(i)) * bspline(t, i, k-1, r)\n end if\n if (t(i+k)-t(i+1) > tiny(1._dp)) then\n B = B - (k-1) / (t(i+k)-t(i+1)) * bspline(t, i+1, k-1, r)\n end if\nend if\nend function\n\npure function bspline_der2(t, i, k, r) result(B)\n! Returns values of a second derivative of a B-spline.\n! There are set of `n` B-splines of order `k`. The mesh is composed of `n+k`\n! knots, stored in the t(:) array.\nreal(dp), intent(in) :: t(:) ! {t_i}, i = 1, 2, ..., n+k\ninteger, intent(in) :: i ! i = 1..n ?\ninteger, intent(in) :: k ! Order of the spline k = 1, 2, 3, ...\nreal(dp), intent(in) :: r(:) ! points to evaluate the spline at\nreal(dp) :: B(size(r))\nif (k == 1) then\n B = 0\nelse\n B = 0\n if (t(i+k-1)-t(i) > tiny(1._dp)) then\n B = B + (k-1) / (t(i+k-1)-t(i)) * bspline_der(t, i, k-1, r)\n end if\n if (t(i+k)-t(i+1) > tiny(1._dp)) then\n B = B - (k-1) / (t(i+k)-t(i+1)) * bspline_der(t, i+1, k-1, r)\n end if\nend if\nend function\n\nend module\n", "meta": {"hexsha": "ed6f14fc9394659d87e43b2418a302422ad5515b", "size": 2981, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/modules_01.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": "tests/modules_01.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-03-25T04:59:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-06-06T23:00:09.000Z", "max_forks_repo_path": "tests/modules_01.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.3789473684, "max_line_length": 78, "alphanum_fraction": 0.5377390138, "num_tokens": 1140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474207360066, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.8075767714294126}} {"text": "! Created by EverLookNeverSee@GitHub on 6/6/20\n! For more information see FCS/img/Exercise_08_d.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\n\nprogram main\n implicit none\n ! x --> given value that we're gonna calculate its arcsin\n ! total --> sum of the elements in series\n ! previous --> sum of elements in previous step\n ! fact --> declaration of fact function\n ! Ea --> approximation error\n ! declaring and initializing variables\n integer :: k = 0\n real :: x = 0.5, total = 0.0, Ea, previous, fact\n do\n ! Adding up first element of series -> `x` itself\n if (k == 0) then\n total = total + x\n k = k + 1\n else ! Calculating and adding up rest of elements of series\n previous = total\n total = total + (fact(2 * k) * x ** (2 * k + 1) &\n / (2 ** (2 * k) * fact(k) ** 2 * (2 * k + 1)))\n Ea = total - previous\n ! Exit whenever approximation error is less than 10e-10\n if (Ea < 10e-10) then\n exit\n else ! keep going to calculate and add up next element of series\n k = k + 1\n cycle\n end if\n end if\n end do\n ! printing and comparing results\n print *, \"Total(aka arcsin):\", total\n print *, \"Fortran intrinsic arcsin function:\", ASIN(x)\nend program main", "meta": {"hexsha": "3e20c306e1aab1556cc19add2c6471d98fa65f2e", "size": 1728, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_08_d.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_d.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_d.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.0, "max_line_length": 77, "alphanum_fraction": 0.5376157407, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.807522714485343}} {"text": "module linalg\n contains\n ! FlK: math helpers\n !> Determinant of a 3x3 matrix, doubles\n pure function determinant_3x3_real(a) result(det)\n real*8, dimension(3,3), intent(in) :: a\n real*8 :: det\n !\n det = a(1,1)*(a(2,2)*a(3,3) - a(3,2)*a(2,3)) &\n + a(1,2)*(a(3,1)*a(2,3) - a(2,1)*a(3,3)) &\n + a(1,3)*(a(2,1)*a(3,2) - a(3,1)*a(2,2))\n end function\n\n !> Trace of a 3x3 matrix, doubles\n pure function trace_3x3_real(a) result(trace)\n real*8, dimension(3,3), intent(in) :: a\n real*8 :: trace\n !\n trace = (a(1,1) + a(2,2) + a(3,3)) / 3.d0\n end function\n\n !> Frobenius norm of a 3x3 matrix, doubles\n pure function frobnorm_3x3_real(a) result(frob)\n real*8, dimension(3,3), intent(in) :: a\n real*8 :: frob\n !\n frob = sqrt(trace_3x3_real(matmul(a, transpose(a))))\n end function\n\n !> Inverse of 3x3 matrix\n pure function matinv3x3(A) result(B)\n real(8), intent(in) :: A(3,3) !! Matrix\n real(8) :: B(3,3) !! Inverse matrix\n real(8) :: detinv\n\n ! Calculate the inverse determinant of the matrix\n detinv = 1/(A(1,1)*A(2,2)*A(3,3) - A(1,1)*A(2,3)*A(3,2)&\n - A(1,2)*A(2,1)*A(3,3) + A(1,2)*A(2,3)*A(3,1)&\n + A(1,3)*A(2,1)*A(3,2) - A(1,3)*A(2,2)*A(3,1))\n\n ! Calculate the inverse of the matrix\n B(1,1) = +detinv * (A(2,2)*A(3,3) - A(2,3)*A(3,2))\n B(2,1) = -detinv * (A(2,1)*A(3,3) - A(2,3)*A(3,1))\n B(3,1) = +detinv * (A(2,1)*A(3,2) - A(2,2)*A(3,1))\n B(1,2) = -detinv * (A(1,2)*A(3,3) - A(1,3)*A(3,2))\n B(2,2) = +detinv * (A(1,1)*A(3,3) - A(1,3)*A(3,1))\n B(3,2) = -detinv * (A(1,1)*A(3,2) - A(1,2)*A(3,1))\n B(1,3) = +detinv * (A(1,2)*A(2,3) - A(1,3)*A(2,2))\n B(2,3) = -detinv * (A(1,1)*A(2,3) - A(1,3)*A(2,1))\n B(3,3) = +detinv * (A(1,1)*A(2,2) - A(1,2)*A(2,1))\n end function\nend module linalg\n\n", "meta": {"hexsha": "99022589b3c40993744e84e8d8b5fbd5288229bb", "size": 1839, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "c_bindings/f2py/linalg.f90", "max_stars_repo_name": "flokno/python_recipes", "max_stars_repo_head_hexsha": "a09da65528ce3a2f1fd884aea361275b9aab0c15", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-06T14:38:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T09:43:04.000Z", "max_issues_repo_path": "c_bindings/f2py/linalg.f90", "max_issues_repo_name": "flokno/python_recipes", "max_issues_repo_head_hexsha": "a09da65528ce3a2f1fd884aea361275b9aab0c15", "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": "c_bindings/f2py/linalg.f90", "max_forks_repo_name": "flokno/python_recipes", "max_forks_repo_head_hexsha": "a09da65528ce3a2f1fd884aea361275b9aab0c15", "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": 34.0555555556, "max_line_length": 60, "alphanum_fraction": 0.5040783034, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9740426428022032, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.8074217434624477}} {"text": "program LU\nuse procedures\nimplicit none\n\nreal(kind=8), allocatable, dimension(:,:) :: a, m, b_test, x_test, a_test\nreal(kind=8), allocatable, dimension(:) :: b, x, y\nreal(kind=8) :: some_number\ninteger :: n, i, j, io\n\nwrite(*,*)\n\n! Determine dimensions of a and b;\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), b(n), b_test(n,1), x_test(n,1), a_test(n,n))\n\n! Assign the elements of a and b:\nrewind(2)\ndo i = 1, n\n read(2,*) (a(i,j), j = 1,n)\nend do\nclose(2)\n\nopen (unit=3, file='b.txt', status='old', action='read')\nread(3,*) (b(j), j = 1,n)\nclose(3)\n\nwrite(*,*) \"the matrix a:\"\ncall writes2d(a)\nwrite(*,*) \"the matrix b:\"\ncall writes1d(b)\n\n! Save the elements of a:\ndo i = 1, n\n do j = 1, n\n a_test(i,j) = a(i,j)\n end do\nend do\n\n! Perform the Gauss Elimination:\ncall Gauss_Elimination(a, n, m)\n\n! Perform Forward and Back Substitution:\ncall Forward_Substitution(m, b, n, y)\nwrite(*,*) \nwrite(*,*) \"-----------------------------------\"\nwrite(*,*) \"[L][Y] = [b]: \"\nwrite(*,*) \"-----------------------------------\"\ncall writes1d(y)\ncall Back_Substitution(a, y, n, x)\nwrite(*,*)\nwrite(*,*) \"-----------------------------------\"\nwrite(*,*) \"[U][X] = [b]: \"\nwrite(*,*) \"-----------------------------------\"\ncall writes1d(x)\n\n! Test the result:\ndo i = 1, n\n x_test(i,1) = x(i)\nend do\nb_test = matmul(a_test,x_test)\nwrite(*,*)\nwrite(*,*) \"-----------------------------------\"\nwrite(*,*) \"[a][x] = \"\ncall writes2d (b_test)\ncall writes1d(b)\nwrite(*,*) \"-----------------------------------\"\n\nend program LU\n", "meta": {"hexsha": "478c6c08fb4bfd91e8e8b4a4407fc9c730a59751", "size": 1690, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW5/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/HW5/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/HW5/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": 21.9480519481, "max_line_length": 73, "alphanum_fraction": 0.5213017751, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.8073651107257863}} {"text": "module mod_determinant\n#include \n use mod_kinds, only: rk,ik,rdouble,rsingle\n use mod_constants, only: ONE\n implicit none\n\n\n\ncontains\n\n\n !> Compute and return the determinant of a 3x3 matrix.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 8/14/2017\n !!\n !!\n !----------------------------------------------------------\n function det_3x3(mat) result(det)\n real(rk), intent(in) :: mat(3,3)\n\n real(rk) :: det\n\n det = mat(1,1)*mat(2,2)*mat(3,3) - mat(1,2)*mat(2,1)*mat(3,3) - &\n mat(1,1)*mat(2,3)*mat(3,2) + mat(1,3)*mat(2,1)*mat(3,2) + &\n mat(1,2)*mat(2,3)*mat(3,1) - mat(1,3)*mat(2,2)*mat(3,1)\n\n end function det_3x3\n !**********************************************************\n\n\n\n\n\n\n\n\nend module mod_determinant\n", "meta": {"hexsha": "54436c80e880932ed1a708f5555a7ff6fcb24aaf", "size": 828, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_determinant.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_determinant.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_determinant.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": 21.2307692308, "max_line_length": 73, "alphanum_fraction": 0.4589371981, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.8071915778465769}} {"text": "program gaussseli\n ! This program simply takes in an nxn matrix, and an nx1 matrix, converts into a reduced row echelon form using gauss jordan pivoting,\n ! ,then calculates the determinant of nxn, if determinant is non-singular the program proceeds to calculate inverse\n ! and solution of (nXn) x = (nX1) form equation (i.e. Ax=b)\n !Various parts of the code are highlighted by comments as to what they do.\n implicit none\n integer :: n,i,k,j\n real , allocatable :: A(:,:), temp(:)\n real :: q, ep=10**(-7)\n print*, \"Give the dimension of matrix A in form AX=b\"\n read*, n\n allocate(A(n,n+1+n), temp(n+n+1)) !Allocate nxn for original matrix, nx1 for b, nxn for I all concatenated\n !!!!!!!!!!!!!!!!!!!!!!!!!!!! READING MATRIX FROM USER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n print*, \"Give the rows of matrix A\"\n do i=1,n\n read*, A(i,1:n)\n enddo\n print*,\"Give values of b\"\n do i=1,n\n read*, A(i,n+1)\n enddo\n !!!!!!!!!!!!! MATRIX FORM IS A(augmented) = A(read)|b(read)|I CONCATENATED AND PROCESSED TOGETHER THROUGHOUT !!!!!!!!!!!!!!\n do i=1,n\n A(i,n+i+1) =1 !getting the identity of the third part in matrix\n enddo\n print*, \"MATRIX = A | b | Identity\"\n do i=1,n\n print*,A(i,:)\n enddo\n print*, \"================================================\"\n !!!!!!!!!!!!!!!! CONVERTING THE MATRIX TO UPPER TRIANGULAR REDUCED ECHELON !!!!!!!!!!!!!!!!!!!\n do k = 1,n\n do i=k,n\n if (abs(A(i,k)) .gt. abs(A(k,k))) then\n temp = A(k,:) ; A(k,:) = A (i,:); A(i,:) = temp !swapping higher terms to higher position in matrix\n endif\n enddo\n do j=k+1,n\n q=(A(j,k))/A(k,k)\n do i=k,n+n+1\n A(j,i) = A(j,i) - q* A(k,i) !finally making the lower triangular terms zero\n enddo\n enddo\n enddo\n !!!!!!!!!!!!!!!!!!!!!!!!! CONVERSION DONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n print*, \"The modified/augmented matrix:\"\n do i=1,n\n print*,A(i,:)\n enddo\n print*, \"=====================================================\"\n !!!!!!!!!! CHECK DETERMINANT AFTER REDUCING IT TO UPPER TRIANGULAR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n print*, \"Checking determinant\"\n q = 1 ! determinant\n do i=1,n\n q = q * A(i,i) !determinant is simply the product of diagonal elements in upper diagonal\n enddo\n print*, \"The determinant is:\", q\n If (abs(q) .le. ep) then \n print*, \"Determinant is SINGULAR, unsolvable\"\n STOP\n endif\n print*, \"=====================================================\"\n !!!!!!!!!!!!!!!!!!!!!!!!!!!CALCULATE FINAL RESULT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n temp =0\n temp(n) = (A(n,n+1))/A(n,n)\n do i = n-1,1,-1\n q=0\n do j=i+1,n\n q = q + A(i,j)*temp(j)\n enddo\n temp(i)= (A(i,n+1) -q)/A(i,i)\n enddo\n print*, \"The solutions are\", temp(1:n)\n print*, \"=========================================================\"\n !!!!!!!!!!!!!!!!!!!!!!!!!!!! COMPUTE INVERSE NOW !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n print*, \"The inverse of A is\"\n do i = n,1,-1\n A(i,:) = A(i,:)/A(i,i)\n enddo\n do i = n,1,-1\n do j=1,i-1\n A(j,:) = A(j,:) - A(i,:)*A(j,i)\n enddo\n enddo\n do i=1,n\n print*,A(i,n+2:)\n enddo\n print*, \"=========================================================\" \nend program gaussseli\n\n", "meta": {"hexsha": "7a7acedeeb6dc55c83482dd4e1db83651c85c0a8", "size": 3517, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gausseli.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": "gausseli.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": "gausseli.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.6483516484, "max_line_length": 138, "alphanum_fraction": 0.4424225192, "num_tokens": 981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.8069794409807689}} {"text": "! Function for matrix product C=A*B\r\n! Optimized memory access pattern is considered.\r\n! In Fortran matrices should be accessed column by column.\r\n! Igor Lopes, February 2015\nSUBROUTINE MATPRD(A,B,C,NROWA,NCOLA,NCOLB)\n IMPLICIT NONE\n ! Parameter\n REAL(8) R0 /0.0D0/\n ! Arguments\n INTEGER :: NROWA , NCOLA , NCOLB\n REAL(8), DIMENSION(NROWA,NCOLA) :: A\n REAL(8), DIMENSION(NCOLA, NCOLB) :: B\n REAL(8), DIMENSION(NROWA,NCOLB) :: C\n ! Locals\n INTEGER I, J, K\n ! Begin algorithm\r\n C=R0\n DO J=1,NCOLB\n\t DO K=1,NCOLA\n\t\t DO I=1,NROWA\n\t\t\t C(I,J)=C(I,J)+A(I,K)*B(K,J)\n\t\t ENDDO\n\t ENDDO\n ENDDO\nEND SUBROUTINE", "meta": {"hexsha": "04c29b9cea0d369c3c814bf4b9f455fabe460ed8", "size": 655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/matprd.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/matprd.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/matprd.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": 26.2, "max_line_length": 59, "alphanum_fraction": 0.6213740458, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8069794404157621}} {"text": "\tFUNCTION PR_VAPR ( dwpc )\nC************************************************************************\nC* PR_VAPR\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes VAPR from DWPC. 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* VAPR = 6.112 * EXP [ (17.67 * DWPC) / (DWPC + 243.5) ]\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 will compute VAPS if TMPC is input.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_VAPR ( 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*\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_VAPR\t\tREAL\t\tVapor pressure in millibars\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\t\t\t\t\t\t*\nC* M. Goodman/RDS\t 4/84\tUpdated prologue and added PR_TMCK\t*\nC* I. Graffman/RDS\t11/84\tUpdated to use Bolton eqn.\t\t*\nC* G. Huffman/GSC\t 8/88\tDocumentation; test for low DWPC\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( dwpc ) .or. ( dwpc .lt. -240. ) ) THEN\n\t PR_VAPR = RMISSD\n\t ELSE\n\t PR_VAPR = 6.112 * EXP (( 17.67 * dwpc ) / ( dwpc + 243.5 ))\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "a4a3da37527591babe31049fd02c3060fc127b34", "size": 1245, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prvapr.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/prvapr.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/prvapr.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.9230769231, "max_line_length": 73, "alphanum_fraction": 0.4409638554, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377296574668, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.8069216484877445}} {"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_sp(y, dx) result(integral)\n real(sp), dimension(:), intent(in) :: y\n real(sp), intent(in) :: dx\n real(sp) :: integral\n\n integer :: n\n\n n = size(y)\n \n select case (n)\n case (0:1)\n integral = 0.0_sp\n case (2)\n integral = 0.5_sp*dx*(y(1) + y(2))\n case default\n integral = dx*(sum(y(2:n-1)) + 0.5_sp*(y(1) + y(n)))\n end select\n end function trapz_dx_sp\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 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\n integer :: n\n\n n = size(y)\n \n select case (n)\n case (0:1)\n integral = 0.0_qp\n case (2)\n integral = 0.5_qp*dx*(y(1) + y(2))\n case default\n integral = dx*(sum(y(2:n-1)) + 0.5_qp*(y(1) + y(n)))\n end select\n end function trapz_dx_qp\n \n\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\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_sp\n case (2)\n integral = 0.5_sp*(x(2) - x(1))*(y(1) + y(2))\n case default\n integral = 0.0_sp\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_sp*integral\n end select\n end function trapz_x_sp\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 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\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_qp\n case (2)\n integral = 0.5_qp*(x(2) - x(1))*(y(1) + y(2))\n case default\n integral = 0.0_qp\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_qp*integral\n end select\n end function trapz_x_qp\n\n\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\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_sp\n case (2)\n w = 0.5_sp*(x(2) - x(1))\n case default\n w(1) = 0.5_sp*(x(2) - x(1))\n w(n) = 0.5_sp*(x(n) - x(n-1))\n do i = 2, size(x)-1\n w(i) = 0.5_sp*(x(i+1) - x(i-1))\n end do\n end select\n end function trapz_weights_sp\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\n\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\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_qp\n case (2)\n w = 0.5_qp*(x(2) - x(1))\n case default\n w(1) = 0.5_qp*(x(2) - x(1))\n w(n) = 0.5_qp*(x(n) - x(n-1))\n do i = 2, size(x)-1\n w(i) = 0.5_qp*(x(i+1) - x(i-1))\n end do\n end select\n end function trapz_weights_qp\n\nend submodule stdlib_quadrature_trapz\n", "meta": {"hexsha": "17bbbc9e57c00bce6948fb2dd3ba8669210e9b12", "size": 5778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_quadrature_trapz.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_trapz.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_trapz.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": 25.68, "max_line_length": 87, "alphanum_fraction": 0.4593284874, "num_tokens": 1764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.8067810619337379}} {"text": "module factorial_mod\r\nimplicit none\r\ncontains\r\npure function factorial(n) result(fac)\r\n! n unchanged upon return\r\ninteger, value :: n\r\ninteger :: fac\r\nif (n < 2) then\r\n fac = 1\r\n return\r\nend if\r\nfac = n\r\ndo\r\n n = n - 1\r\n if (n < 2) return\r\n fac = fac * n\r\nend do\r\nend function factorial\r\n!\r\nfunction factorial_impure(n) result(fac)\r\n! poor style -- n changed upon return\r\ninteger :: n\r\ninteger :: fac\r\nif (n < 2) then\r\n fac = 1\r\n return\r\nend if\r\nfac = n\r\ndo\r\n n = n - 1\r\n if (n < 2) return\r\n fac = fac * n\r\nend do\r\nend function factorial_impure\r\nend module factorial_mod\r\n!\r\nprogram test_factorial\r\nuse factorial_mod\r\nimplicit none\r\ninteger :: n = 4\r\nprint*,factorial(n) ! 24\r\nprint*,n ! 4\r\nprint*,factorial_impure(n) ! 24\r\nprint*,n ! 1\r\nend program test_factorial", "meta": {"hexsha": "a2884147c34c6c772ce0b07ef681aa8d8a1d26e0", "size": 791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "value.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": "value.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": "value.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": 17.5777777778, "max_line_length": 41, "alphanum_fraction": 0.6396965866, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8902942246666266, "lm_q1q2_score": 0.80659750469412}} {"text": "c####&\n\nc Matrix operation subroutines\n\n\n\nc --- generic real matrix linear combination. xA+yB=C, all mXn\n subroutine rmatlincomb(x,A,y,B,C,m,n)\n \n implicit none\n integer i,j,m,n\n real x,A(m,n),y,B(m,n),C(m,n)\n \n do i=1,m\n do j=1,n\n C(i,j)=x*A(i,j)+y*B(i,j)\n end do\n end do\n \n end\n \nc --- generic compled matrix linear combination. xA+yB=C, all mXn\n subroutine cmatlincomb(x,A,y,B,C,m,n)\n \n implicit none\n integer i,j,m,n\n complex x,A(m,n),y,B(m,n),C(m,n)\n \n do i=1,m\n do j=1,n\n C(i,j)=x*A(i,j)+y*B(i,j)\n end do\n end do\n \n end\n\nc --- Generic real matrix-constant multiply. A=c*A, A:mxn\n subroutine rmatconst(A,c,m,n)\n \n implicit none\n integer m,n,i,j\n real A(m,n),c\n \n do i=1,m\n do j=1,n\n A(i,j)=c*A(i,j)\n end do\n end do\n \n end\n \n \nc --- Generic complex matrix-constant multiply. A=c*A, A:mxn\n subroutine cmatconst(A,c,m,n)\n \n implicit none\n integer m,n,i,j\n complex A(m,n),c\n \n do i=1,m\n do j=1,n\n A(i,j)=c*A(i,j)\n end do\n end do\n \n end\n \n \nc --- Generic real matrix multiplication, A*B=C. A:mXn, B:nXo, C:mXo\n subroutine rmatmul(a,b,c,m,n,o)\n \n implicit none\n integer n,m,o,i,j,k\n real a(m,n),b(n,o),c(m,o)\n\n do i=1,m\n do j=1,o\n c(i,j)=0\n do k=1,n\n c(i,j)=c(i,j)+a(i,k)*b(k,j)\n end do\n end do\n end do\n \n end\n \n \nc --- Generic complex matrix multiplication, A*B=C. A:mXn, B:nXo, C:mXo\n subroutine cmatmul(a,b,c,m,n,o)\n \n implicit none\n integer n,m,o,i,j,k\n complex a(m,n),b(n,o),c(m,o)\n\n do i=1,m\n do j=1,o\n c(i,j)=0\n do k=1,n\n c(i,j)=c(i,j)+a(i,k)*b(k,j)\n end do\n end do\n end do\n \n end \n \n \nc --- Generic real matrix-vector multiply, Ax=y. A:mXn,x:n,y:m\n subroutine rmatvec(a,x,y,m,n)\n \n implicit none\n integer m,n,i,j\n real a(m,n),x(n),y(m)\n \n do i=1,m\n y(i)=0\n do j=1,n\n y(i)=y(i)+a(i,j)*x(j)\n end do\n end do\n \n end\n \n \nc --- Generic complex matrix-vector multiply, Ax=y. A:mXn,x:n,y:m\n subroutine cmatvec(a,x,y,m,n)\n \n implicit none\n integer m,n,i,j\n complex a(m,n),x(n),y(m)\n \n do i=1,m\n y(i)=0\n do j=1,n\n y(i)=y(i)+a(i,j)*x(j)\n end do\n end do\n \n end\n \n \nc --- 3x3 real matrix linear combination. xA+yB=C\n subroutine rmatlincomb3(x,A,y,B,C)\n \n implicit none\n integer i,j\n real x,A(3,3),y,B(3,3),C(3,3)\n \n do i=1,3\n do j=1,3\n C(i,j)=x*A(i,j)+y*B(i,j)\n end do\n end do\n \n end\n \n \nc --- 3x3 complex matrix linear combination. xA+yB=C\n subroutine cmatlincomb3(x,A,y,B,C)\n \n implicit none\n integer i,j\n complex x,A(3,3),y,B(3,3),C(3,3)\n \n do i=1,3\n do j=1,3\n C(i,j)=x*A(i,j)+y*B(i,j)\n end do\n end do\n \n end\n \n \nc --- 3x3 matrix-constant multiply. A=c*A\n subroutine rmatconst3(A,c)\n \n implicit none\n real A(3,3),c\n integer i,j\n \n do i=1,3\n do j=1,3\n A(i,j)=c*A(i,j)\n end do\n end do\n \n end\n\n \nc --- 3x3 complex matrix-constant multiply. A=c*A\n subroutine cmatconst3(A,c)\n \n implicit none\n complex A(3,3),c\n integer i,j\n \n do i=1,3\n do j=1,3\n A(i,j)=c*A(i,j)\n end do\n end do\n \n end\n \n \nc --- 3x3 real matrix multiplication, A*B=C \n subroutine rmatmul3(a,b,c)\n \n implicit none\n real a(3,3),b(3,3),c(3,3)\n integer i,j,k\n \n do i=1,3\n do j=1,3\n c(i,j)=0\n do k=1,3\n c(i,j)=c(i,j)+a(i,k)*b(k,j)\n end do\n end do\n end do\n \n end\n\nc --- 3x3 complex matrix multiplication, A*B=C \n subroutine cmatmul3(a,b,c)\n \n implicit none\n complex a(3,3),b(3,3),c(3,3)\n integer i,j,k\n \n do i=1,3\n do j=1,3\n c(i,j)=0\n do k=1,3\n c(i,j)=c(i,j)+a(i,k)*b(k,j)\n end do\n end do\n end do\n \n end\n \n \nc --- 3x3 real matrix-vector multiplication,Ax=y\n subroutine rmatvec3(a,x,y)\n \n implicit none\n real a(3,3),x(3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+a(i,j)*x(j)\n end do\n end do\n \n end\n\n \nc --- 3x3 complex matrix-vector multiplication,Ax=y\n subroutine cmatvec3(a,x,y)\n \n implicit none\n complex a(3,3),x(3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+a(i,j)*x(j)\n end do\n end do\n \n end\n \nc --- 3x3 real/complex matrix-vector multiplication, complex output\n subroutine rcmatvec3(a,x,y)\n \n implicit none\n real a(3,3)\n complex x(3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+cmplx(a(i,j))*x(j)\n end do\n end do\n \n end\n \nc --- 3x3 complex/real matrix-vector multiplication, real output\n subroutine crmatvec3(a,x,y)\n \n implicit none\n complex a(3,3)\n real x(3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+real(a(i,j))*x(j)\n end do\n end do\n \n end\n\nc --- 3x3 real vector-matrix multiplication, x'A=y\n subroutine rvecmat3(x,a,y)\n \n implicit none\n real x(3),a(3,3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+x(j)*a(j,i)\n end do\n end do\n \n end\n \n \nc --- 3x3 complex vector-matrix multiplication, x'A=y\n subroutine cvecmat3(x,a,y)\n \n implicit none\n complex x(3),a(3,3),y(3)\n integer i,j\n \n do i=1,3\n y(i)=0\n do j=1,3\n y(i)=y(i)+x(j)*a(j,i)\n end do\n end do\n \n end\n \nc --- Real dot product, 3-vectors, z=x.y\n real function rdot3(x,y)\n \n implicit none\n real x(3),y(3)\n \n rdot3=x(1)*y(1)+x(2)*y(2)+x(3)*y(3)\n \n end\n \nc --- Complex dot product, 3-vectors, z=x.y \n complex function cdot3(x,y)\n \n implicit none\n complex x(3),y(3)\n \n cdot3=conjg(x(1))*y(1)+conjg(x(2))*y(2)+conjg(x(3))*y(3)\n \n end\n \n\n \nc --- Real 3x3 matrix inverse. ai=a^(-1)\nc Adapted from Thompson's routine; based on cofactors.\n subroutine rmatinv3(a,ai)\n \n implicit none\n real a(3,3),ai(3,3),co(3,3),det\n integer i,j\n \n co(1,1)=(a(2,2)*a(3,3)-a(2,3)*a(3,2))\n co(1,2)=-(a(2,1)*a(3,3)-a(2,3)*a(3,1))\n co(1,3)=(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n co(2,1)=-(a(1,2)*a(3,3)-a(1,3)*a(3,2))\n co(2,2)=(a(1,1)*a(3,3)-a(1,3)*a(3,1))\n co(2,3)=-(a(1,1)*a(3,2)-a(1,2)*a(3,1))\n co(3,1)=(a(1,2)*a(2,3)-a(1,3)*a(2,2))\n co(3,2)=-(a(1,1)*a(2,3)-a(1,3)*a(2,1))\n co(3,3)=(a(1,1)*a(2,2)-a(1,2)*a(2,1))\n det=a(1,1)*co(1,1)+a(1,2)*co(1,2)+a(1,3)*co(1,3)\n do i=1,3\n do j=1,3\n ai(i,j)=co(j,i)/det\n end do\n end do\n \n end\n\nc --- Complex 3x3 matrix inverse. ai=a^(-1)\nc Adapted from Thompson's routine; based on cofactors.\n subroutine cmatinv3(a,ai)\n \n implicit none\n complex a(3,3),ai(3,3),co(3,3),det\n integer i,j\n \n co(1,1)=(a(2,2)*a(3,3)-a(2,3)*a(3,2))\n co(1,2)=-(a(2,1)*a(3,3)-a(2,3)*a(3,1))\n co(1,3)=(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n co(2,1)=-(a(1,2)*a(3,3)-a(1,3)*a(3,2))\n co(2,2)=(a(1,1)*a(3,3)-a(1,3)*a(3,1))\n co(2,3)=-(a(1,1)*a(3,2)-a(1,2)*a(3,1))\n co(3,1)=(a(1,2)*a(2,3)-a(1,3)*a(2,2))\n co(3,2)=-(a(1,1)*a(2,3)-a(1,3)*a(2,1))\n co(3,3)=(a(1,1)*a(2,2)-a(1,2)*a(2,1))\n det=a(1,1)*co(1,1)+a(1,2)*co(1,2)+a(1,3)*co(1,3)\n do i=1,3\n do j=1,3\n ai(i,j)=co(j,i)/det\n end do\n end do\n \n end \n \n\nc --- Generic real matrix transpose, B=transpose of A. A: mxn,B:nxm\n subroutine rtransp(A,B,m,n)\n \n implicit none\n integer m,n,i,j\n real a(m,n),b(n,m)\n \n do i=1,m\n do j=1,n\n b(j,i)=a(i,j)\n end do\n end do\n \n end\n \nc --- Generic complex matrix transpose, B=transpose of A. A: mxn,B:nxm\n subroutine ctransp(A,B,m,n)\n \n implicit none\n integer m,n,i,j\n complex a(m,n),b(n,m)\n \n do i=1,m\n do j=1,n\n b(j,i)=a(i,j)\n end do\n end do\n \n end\n \nc --- 3x3 real matrix transpose, B=transpose of A.\n subroutine rtransp3(A,B)\n \n implicit none\n integer i,j\n real a(3,3),b(3,3)\n \n do i=1,3\n do j=1,3\n b(j,i)=a(i,j)\n end do\n end do\n \n end \n \nc --- 3x3 complex matrix transpose, B=transpose of A.\n subroutine ctransp3(A,B)\n \n implicit none\n integer i,j\n complex a(3,3),b(3,3)\n \n do i=1,3\n do j=1,3\n b(j,i)=a(i,j)\n end do\n end do\n \n end \n \n\n\nc --- Real matrix copy, arbitrary dimensions. A is copied to B, both mXn\n subroutine rmatcopy(a,b,m,n)\n \n implicit none\n integer m,n,i,j\n real a(m,n),b(m,n)\n \n do i=1,m\n do j=1,n\n b(i,j)=a(i,j)\n end do\n end do\n \n end\n \nc --- Complex matrix copy, arbitrary dimensions. A is copied to B, both mXn\n subroutine cmatcopy(a,b,m,n)\n \n implicit none\n integer m,n,i,j\n complex a(m,n),b(m,n)\n \n do i=1,m\n do j=1,n\n b(i,j)=a(i,j)\n end do\n end do\n \n end\n\nc --- 3x3 real matrix copy. A is copied to B.\n subroutine rmatcopy3(a,b)\n \n implicit none\n integer i,j\n real a(3,3),b(3,3)\n \n do i=1,3\n do j=1,3\n b(i,j)=a(i,j)\n end do\n end do\n \n end\n \nc --- 3x3 complex matrix copy. A is copied to B.\n subroutine cmatcopy3(a,b)\n \n implicit none\n integer i,j\n complex a(3,3),b(3,3)\n \n do i=1,3\n do j=1,3\n b(i,j)=a(i,j)\n end do\n end do\n \n end\n \n \nc --- Real vector copy, arbitrary dimention. x is copied to y, dimension n\n subroutine rveccopy(x,y,n)\n \n implicit none\n integer n,i\n real x(n),y(n)\n \n do i=1,n\n y(i)=x(i)\n end do\n \n end\n \nc --- Complex vector copy, arbitrary dimention. x is copied to y, dimension n\n subroutine cveccopy(x,y,n)\n \n implicit none\n integer n,i\n complex x(n),y(n)\n \n do i=1,n\n y(i)=x(i)\n end do\n \n end \n \nc --- Extract column vector v from real matrix A.\nc v=A(i1:i2,k), A:mXn, v:i2-i1+1\n subroutine rextractvec(a,v,i1,i2,k,m,n)\n \n implicit none\n integer i1,i2,k,m,n,i\n real a(m,n),v(i2-i1+1)\n \n do i=i1,i2\n v(i-i1+1)=a(i,k)\n end do\n \n end\n \nc --- Extract column vector v from complex matrix A.\nc v=A(i1:i2,k), A:mXn, v:i2-i1+1\n subroutine cextractvec(a,v,i1,i2,k,m,n)\n \n implicit none\n integer i1,i2,k,m,n,i\n complex a(m,n),v(i2-i1+1)\n \n do i=i1,i2\n v(i-i1+1)=a(i,k)\n end do\n \n end \n \nc --- Extract submatrix B from real matrix A. B=A(i1:i2,j1:j2). A is mxn\n subroutine rextractblock(a,b,i1,i2,j1,j2,m,n)\n \n implicit none\n integer i1,i2,j1,j2,m,n,ii,jj\n real a(m,n),b(i2-i1+1,j2-j1+1)\n \n do ii=i1,i2\n do jj=j1,j2\n b(ii-i1+1,jj-j1+1)=a(ii,jj)\n end do\n end do\n \n end\n \nc --- Extract submatrix B from complex matrix A. B=A(i1:i2,j1:j2). A is mxn\n subroutine cextractblock(a,b,i1,i2,j1,j2,m,n)\n \n implicit none\n integer i1,i2,j1,j2,m,n,ii,jj\n complex a(m,n),b(i2-i1+1,j2-j1+1)\n \n do ii=i1,i2\n do jj=j1,j2\n b(ii-i1+1,jj-j1+1)=a(ii,jj)\n end do\n end do\n \n end \n \nc --- Find index and value of highest-magnitude (absolute-value max)\nc element in real vector v. v:m elements. In case of equality,\nc finds first element.\n subroutine rmax_vec_abs(v,index,value,m)\n \n implicit none\n integer index,m,j\n real v(m),value\n \n value=abs(v(1))\n index=1\n do j=2,m\n if (abs(v(j)) .gt. value) then\n value=abs(v(j))\n index=j\n end if\n end do\n \n end\n \nc --- Find index and value of highest-magnitude (absolute-value max)\nc element in complex vector v. v:m elements. In case of equality,\nc finds first element.\n subroutine cmax_vec_abs(v,index,value,m)\n \n implicit none\n integer index,m,j\n complex v(m)\n real value\n \n value=abs(v(1))\n index=1\n do j=2,m\n if (abs(v(j)) .gt. value) then\n value=abs(v(j))\n index=j\n end if\n end do\n \n end\n \n \nc --- Normalize a real 3-vector to 1. y=x/||x||\n subroutine rnorm3(x,y)\n \n implicit none\n real x(3),y(3),norm\n \n norm=sqrt(x(1)*x(1)+x(2)*x(2)+x(3)*x(3))\n if (norm .ne. 0) then\n y(1)=x(1)/norm\n y(2)=y(2)/norm\n y(3)=y(3)/norm\nc else\nc write (*,*) 'rnorm3: Norm is zero'\n end if\n \n end\n \nc --- Normalize a complex 3-vector to 1. y=x/||x||\n subroutine cnorm3(x,y)\n \n implicit none\n complex x(3),y(3),norm\n \n norm=sqrt(x(1)*x(1)+x(2)*x(2)+x(3)*x(3))\n if (norm .ne. 0) then\n y(1)=x(1)/norm\n y(2)=y(2)/norm\n y(3)=y(3)/norm\n end if\n \n end \n \nc --- Print a generic real MxN matrix.\n subroutine rprintmat(A,m,n)\n \n implicit none\n integer m,n,i,j\n real A(m,n)\n character*9 fmt\n parameter (fmt='(G14.6,$)')\n \n do i=1,m\n do j=1,n\n write(*,fmt) A(i,j)\n end do\n write(*,*)\n end do\n \n end\n \nc --- Print a generic complex MxN matrix.\n subroutine cprintmat(A,m,n)\n \n implicit none\n integer m,n,i,j\n complex A(m,n)\n \n do i=1,m\n do j=1,n\n write(*,'(X,''('',G14.6,'','',G14.6,'')'',$)')\n & real(A(i,j)),aimag(A(i,j))\n end do\n write(*,*)\n end do\n \n end\n", "meta": {"hexsha": "14a42775c8ef2bf88ec01114b16387cd65de0b1e", "size": 15904, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pyraysum/src/matrixops.f", "max_stars_repo_name": "xumi1993/PyRaysum", "max_stars_repo_head_hexsha": "d7424957072b7ffd41a993ccba9903355c98a449", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-12-03T06:19:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T07:19:34.000Z", "max_issues_repo_path": "pyraysum/src/matrixops.f", "max_issues_repo_name": "xumi1993/PyRaysum", "max_issues_repo_head_hexsha": "d7424957072b7ffd41a993ccba9903355c98a449", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-11-10T18:57:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T22:26:05.000Z", "max_forks_repo_path": "pyraysum/src/matrixops.f", "max_forks_repo_name": "xumi1993/PyRaysum", "max_forks_repo_head_hexsha": "d7424957072b7ffd41a993ccba9903355c98a449", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-12-03T06:20:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T21:04:21.000Z", "avg_line_length": 21.7267759563, "max_line_length": 77, "alphanum_fraction": 0.4200201207, "num_tokens": 5109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.8065379312259319}} {"text": "! calculates the overlap area between a given wake and a rotor area\nsubroutine overlap_area_func(turbine_y, turbine_z, rotor_diameter, &\n wake_center_y, wake_center_z, wake_diameter, &\n wake_overlap)\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) :: turbine_y, turbine_z, rotor_diameter\n real(dp), intent(in) :: wake_center_y, wake_center_z, wake_diameter\n \n ! out \n real(dp), intent(out) :: wake_overlap\n \n ! local\n real(dp), parameter :: pi = 3.141592653589793_dp, tol = 0.000001_dp\n real(dp) :: OVdYd, OVr, OVRR, OVL, OVz\n \n ! load intrinsic functions\n intrinsic acos, sqrt\n \n print *, turbine_y, turbine_z, rotor_diameter, &\n wake_center_y, wake_center_z, wake_diameter, &\n wake_overlap\n \n ! distance between wake center and rotor center\n if (wake_center_z .gt. turbine_z + tol or wake_center_z .lt. turbine_z - tol) then\n OVdYd = sqrt((wake_center_y-turbine_y)**2_dp + (wake_center_z - turbine_z)**2_dp)\n else\n OVdYd = abs(wake_center_y-turbine_y)\n end if\n !print *, \"OVdYd: \", OVdYd\n ! find rotor radius\n OVr = rotor_diameter/2.0_dp\n !print *, \"OVr: \", OVr\n \n ! find wake radius\n OVRR = wake_diameter/2.0_dp\n !print *, \"OVRR: \", OVRR\n \n ! make sure the distance from wake center to turbine hub is positive\n ! OVdYd = abs(OVdYd) !!! commented out since change to 2D distance (y,z) will always be positive\n \n ! calculate the distance from the wake center to the line perpendicular to the \n ! line between the two circle intersection points\n if (OVdYd >= 0.0_dp + tol) then ! check case to avoid division by zero\n! if (OVdYd >= 0.0_dp) then ! check case to avoid division by zero\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\n if (OVz > 0.0_dp + tol) then TODO\n! if (OVz > 0.0_dp) then\n OVz = sqrt(OVz)\n else\n OVz = 0.0_dp\n end if\n \n !print *, \"OVRR, OVL, OVRR, OVr, OVdYd, OVz \", OVRR, OVL, OVRR, OVr, OVdYd, OVz\n \n \n\n if (OVdYd < (OVr+OVRR)) then ! if the rotor overlaps the wake\n !print *, \"OVL: \", OVL\n if (OVL < OVRR .and. (OVdYd-OVL) < OVr) then\n! if (OVdYd > 0.0_dp + tol) then\n! if ((OVdYd > 0.0_dp) .and. (OVdYd > (OVRR - OVr))) then\n ! print *, \"acos(OVL/OVRR), acos((OVdYd-OVL)/OVr), OVRR, OVL, OVr, OVdYd, OVL/OVRR, (OVdYd-OVL)/OVr \", &\n! & acos(OVL/OVRR), acos((OVdYd-OVL)/OVr), OVRR, OVL, OVr, OVdYd, OVL/OVRR, (OVdYd-OVL)/OVr\n wake_overlap = OVRR*OVRR*acos(OVL/OVRR) + OVr*OVr*acos((OVdYd-OVL)/OVr) - OVdYd*OVz\n else if (OVRR > OVr) then\n wake_overlap = pi*OVr*OVr\n !print *, \"wake ovl: \", wake_overlap\n else\n wake_overlap = pi*OVRR*OVRR\n end if\n else\n wake_overlap = 0.0_dp\n end if\n print *, \"wake overlap in func: \", wake_overlap/(pi*OVr**2)\n print *, \"wake overlap in func: \", wake_overlap/(pi*OVRR**2)\n if ((wake_overlap/(pi*OVr**2) > 1.0_dp) .or. (wake_overlap/(pi*OVRR**2) > 1.0_dp)) then\n print *, \"wake overlap in func: \", wake_overlap\n STOP 1\n end if\n \nend subroutine overlap_area_func", "meta": {"hexsha": "983a6acd57dc92060b6db8ca4da986c2dfdb581e", "size": 3586, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gaussianwake/overlap_gauss.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_gauss.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_gauss.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": 38.1489361702, "max_line_length": 116, "alphanum_fraction": 0.5953708868, "num_tokens": 1174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422199928904, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.806537928877172}} {"text": "program tarefa7\n ! Definindo valor de pi\n pi = 4e0*atan(1e0)\n \n ! Variável inteira id que recebe o número da dimensão\n print *, 'Digite o número de dimensões d:'\n read (*,*) id\n \n ! Número M aleátorios \n print *, ''\n print *, 'Digite o número de iterações M:'\n read (*,*) M\n \n ! Contador N de pontos dentro da d-esfera\n N = 0\n \n ! loop de ;m iterações\n do i = 1, M\n ! Variável que irá armazenar o modulo ao quadrado de cada ponto\n rmod = 0\n ! Coordenadas aleátorias do ponto\n do j = 1, id\n rmod = rmod + rand()**2\n end do\n ! Soma +1 em N, se o ponto estiver dentro da d-esfera\n if (rmod.le.1e0) then\n N = N + 1\n end if\n end do\n \n ! Volume obtido pelo metodo de monte carlo\n Vmc = (float(N)/float(M)) * 2e0**id\n \n ! aqui é feita uma mudança de variável para facilitar\n ! arg = d/2 + 1\n ! dgamma(arg) = (arg-1)*dgamma(arg-1)\n arg = (id/2e0 + 1e0)\n dgamma = 1e0\n \n arg = arg - 1e0\n ! O Cálculo da função gamma é reproativo,\n ! então precisa verificar se a última iteração será gamma(1) ou gamma(1/2)\n do while (arg.gt.0e0)\n if (arg.ge.1e0) then\n dgamma = arg*dgamma\n arg = arg - 1e0\n else\n dgamma = arg*sqrt(pi)*dgamma\n arg = 0e0\n end if\n end do\n\n ! Cálculo do volume de d-esfera de raio 1\n Vd = pi**(id/2e0) / dgamma\n \n ! Imprime os volumes da tela\n print '(A,F0.6)', 'Volume por Monte Carlo: ', Vmc\n print '(A,F0.6)', 'Volume por n-esferas: ', Vd\n \nend program tarefa7\n", "meta": {"hexsha": "cf3ca157253ccd5132f38696dcef1f90e47fe264", "size": 1633, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-1/tarefa-7/tarefa-7-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-7/tarefa-7-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-7/tarefa-7-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.7704918033, "max_line_length": 78, "alphanum_fraction": 0.5456215554, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8064712018103484}} {"text": "\n!============================================================\n!> Inverse matrix\n!! Method: Based on Doolittle LU factorization for Ax=b\n!! Original code by Alex G. December 2009\n!! modified by Jongchan Kim 2018\n!!-----------------------------------------------------------\n!! input ...\n!! a(n,n) - array of coefficients for matrix A\n!! n - dimension\n!! output ...\n!! a(n,n) - inverse matrix of A\n!! comments ...\n!! the original matrix a(n,n) will be destroyed \n!! during the calculation\n!!===========================================================\nsubroutine matInverse(a,n)\n\n implicit none\n integer :: n\n real(8) :: a(n,n)\n real(8) :: L(n,n), U(n,n), b(n), d(n), x(n)\n real(8) :: coeff\n integer :: i, j, k\n\n ! step 0: initialization for matrices L and U and b\n ! Fortran 90/95 aloows such operations on matrices\n L=0.d0\n U=0.d0\n b=0.d0\n\n ! step 1: forward elimination\n do 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\n end 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\n do i=1,n\n L(i,i) = 1.d0\n end do\n ! U matrix is the upper triangular part of A\n do j=1,n\n do i=1,j\n U(i,j) = a(i,j)\n end do\n end do\n\n ! Step 3: compute columns of the inverse matrix C\n do k=1,n\n b(k)=1.d0\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 a(i,k) = x(i)\n end do\n b(k)=0.d0\n end do\nend subroutine matInverse\n ", "meta": {"hexsha": "e898177293c4ac3fda8d9185386ff10b36db2aba", "size": 2178, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/libLinearSolver.f90", "max_stars_repo_name": "younglin90/1d_Euler_Hyb_DP", "max_stars_repo_head_hexsha": "c8df50886f9a622c36b808a2812bfdb2aa1140c3", "max_stars_repo_licenses": ["MIT"], "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/libLinearSolver.f90", "max_issues_repo_name": "younglin90/1d_Euler_Hyb_DP", "max_issues_repo_head_hexsha": "c8df50886f9a622c36b808a2812bfdb2aa1140c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-24T07:40:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-24T07:40:29.000Z", "max_forks_repo_path": "lib/libLinearSolver.f90", "max_forks_repo_name": "younglin90/1d_Euler_Hyb_DP", "max_forks_repo_head_hexsha": "c8df50886f9a622c36b808a2812bfdb2aa1140c3", "max_forks_repo_licenses": ["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.2409638554, "max_line_length": 61, "alphanum_fraction": 0.4522497704, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.8064556921317272}} {"text": "! Objetivo: Obter as raizes reais e complexas da equação \n! (terceiro grau) variando o termo independente dentro\n! do intervalo de 5 a 7. Em seguida, verificar resultado.\n\nPROGRAM raizes_reais_complexas\n\tUSE nrtype\n! Declaracao de variaveis\n\tIMPLICIT none\n\tREAL, PARAMETER :: coefic_a = -6., coefic_b = 11., coefic_a_div = coefic_a/3.\n\tREAL, PARAMETER :: coefic_c_inicial = 5., coefic_c_final = 7.\n\tREAL :: raiz_1, raiz_2, raiz_3, raiz_real1, &\n\t\traiz_real2, raiz_real3, coefic_c = coefic_c_inicial\n\tREAL :: raiz_img2, raiz_img3\n\tREAL :: R, A, B, R_exp2, soma_ab, dif_ab\n\tREAL :: theta\n\tINTEGER, PARAMETER :: dados_reais = 7, dados_complexos = 8, &\n\t\tnum_pontos = 1000\n\tINTEGER, PARAMETER :: dados_cx = 9\n\tINTEGER :: num_repetir\n\tREAL, PARAMETER :: incremento_c = (coefic_c_final - &\n\t\tcoefic_c_inicial)/REAL(num_pontos)\n\tREAL :: x_da_curva, c_da_curva\n\tREAL, PARAMETER :: Q = coefic_a_div**2 - coefic_b/3., Q_exp3 = Q**3\n\tREAL, PARAMETER :: parte_R = (coefic_a_div**3) - coefic_a*coefic_b/6.\n\tREAL, PARAMETER :: doisraiz_q = -2.*SQRT(Q), div_1_3 = 1./3., &\n\t\t\t\traiz3_div2 = 0.5*SQRT(3.)\n\t\t\t\t\n! Os valores (iniciais e finais) de x foram calculados\n! por uma calculadora grafica\n\tREAL, PARAMETER :: x_inicial = 0.48, x_final = 3.52, incremento_x &\n\t\t= (x_final - x_inicial)/REAL(num_pontos)\n! Abrindo os arquivos de saida (fora do loop)\n\tOPEN(dados_reais, FILE=\"dados_reais.dat\")\n \tOPEN(dados_complexos, FILE=\"dados_complexos.dat\")\n! Separando a parte dependente de C para otimizar o loop\t\n\tDO num_repetir = 0, num_pontos\n\t\tR = parte_R - 0.5*coefic_c\n\t\tR_exp2 = R**2\n! Primeiro Caso\n\t\tIF (R_exp2 <= Q_exp3) THEN\n\t\t\ttheta = ACOS(R/SQRT(Q_exp3))\n\t\t\traiz_1 = doisraiz_q*COS(theta/3.) - (coefic_a_div)\n\t\t\traiz_2 = doisraiz_q*COS((theta + TWOPI)/3.) - &\n\t\t\t\t(coefic_a_div)\n\t\t\traiz_3 = doisraiz_q*COS((theta - TWOPI)/3.) - &\n\t\t\t\t(coefic_a_div)\n! Escrevendo dentro dos arquivos de saida\n\t\t\tWRITE(dados_reais,*) coefic_c, raiz_1\n\t\t \tWRITE(dados_reais,*) coefic_c, raiz_2\n\t\t \tWRITE(dados_reais,*) coefic_c, raiz_3\n! Segundo Caso\n\t\tELSE\n\t\t\tA = -SIGN(1.0,R)*(ABS(R) + SQRT(R_exp2 - Q_exp3))**div_1_3\t\t\n\t\t\tIF (A /= 0.) THEN\n\t\t\t\tB = Q/A\n\t\t\tELSE\n\t\t\t\tB = 0.\n\t\t\tEND IF\n! Determinando as partes imaginarias e reais de cada raiz\n\t\t\tsoma_ab = A + B\n\t\t\tdif_ab = A - B\n\t\t\traiz_real1 = soma_ab - coefic_a_div\n\t\t\traiz_real2 = -0.5*soma_ab - coefic_a_div\n\t\t\traiz_img2 = raiz3_div2*dif_ab\n\t\t\traiz_real3 = raiz_real2\n\t\t\traiz_img3 = -raiz_img2\n! Escrevendo dentro dos arquivos de saida\n\t\t\tWRITE(dados_reais,*) coefic_c, raiz_real1\n\t\t\tWRITE(dados_complexos,*) raiz_real2, raiz_img2\n\t\t \tWRITE(dados_complexos,*) raiz_real3, raiz_img3\n\t\tEND IF\n! Modificando o valor de c no intervalo proposto\n\t\tcoefic_c = coefic_c + incremento_c\n\tEND DO\n! Fechando os arquivos de saida\n\tCLOSE(dados_reais)\n\tCLOSE(dados_complexos)\n! Abrindo arquivo de saida\n\tOPEN(dados_cx, FILE=\"dados_cx.dat\")\n\tx_da_curva = x_inicial \n\tDO num_repetir = 1, num_pontos\n\t\tc_da_curva = x_da_curva*(coefic_b + (x_da_curva* &\n\t\t\t(x_da_curva + coefic_a)))\n! Modificando o valor de x no intervalo proposto\n\t\tx_da_curva = x_da_curva + incremento_x\n! Escrevendo dentro do arquivo de saida\n\t\tWRITE(dados_cx,*) c_da_curva , x_da_curva \n\tEND DO\n! Fechando arquivo de saida\n\tCLOSE(dados_cx)\nEND PROGRAM raizes_reais_complexas\n", "meta": {"hexsha": "9f35c519d90424e8ad8ee816dc88d52fc2e7e435", "size": 3251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "raizes_reais_complexas.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": "raizes_reais_complexas.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": "raizes_reais_complexas.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.3369565217, "max_line_length": 78, "alphanum_fraction": 0.7123961858, "num_tokens": 1257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739076, "lm_q2_score": 0.8459424392504908, "lm_q1q2_score": 0.806415813776456}} {"text": "!QUADRARIC EQUATION SOLVING\n\nprogram Quadratic_Root\n implicit none\n\n real :: a, b, c, discriminant, real_part, imaginary_part; \n print *, \"Enter the value of a , b and c?\"\n READ *, a, b, c; \n discriminant = b*b - 4*a*c\n\n print *, \"Roots are\"\n\n if (discriminant > 0) then\n\n real_part = -b/(2.0*a)\n imaginary_part = SQRT(discriminant)/(2.0*a)\n\n print '(f4.2,A2,f4.2,A5,f4.2,A2,f4.2)', real_part, \"+\", imaginary_part, \" and \", real_part, \"-\", imaginary_part\n else if (discriminant == 0) then\n\n real_part = -b/(2.0*a)\n imaginary_part = SQRT(discriminant)/(2.0*a)\n\n print '(f4.2,A5,f4.2)', real_part, \" and \", real_part\n\n else if (discriminant < 0) then\n\n real_part = -b/(2.0*a)\n imaginary_part = SQRT(-discriminant)/(2.0*a)\n\n print '(f5.2,A4,f5.2,A5,f4.2,A4,f4.2)', real_part, \" + i\", imaginary_part, \" and \", real_part, \" - i\", imaginary_part\n\n end if\n\nend program Quadratic_Root\n", "meta": {"hexsha": "2dd34405afc04395a68c62b42097b1ff02ca1234", "size": 970, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem02.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": "Problem02.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": "Problem02.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": 26.9444444444, "max_line_length": 125, "alphanum_fraction": 0.5917525773, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750466836961, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.806415810863281}} {"text": "MODULE Gauss\n\n USE PrecTypes\n IMPLICIT NONE \n\n ! -------------------------------------------------------------------------\n ! Name: Gauss\n ! Parent: General\n ! Status: Current\n ! Owner: Toshiro Matsumoto\n ! Text: Coordinates and weights of Gaussian quadrature formula.\n ! Revision Date: 16-Jul-2009\n ! -------------------------------------------------------------------------\n \n ! Offset numbers used in the arrays zt() and wt()\n INTEGER(I4B) :: ngs(6) =(/ 0, 0, 2, 5, 9, 14 /)\n \n ! Coordinates of the integration points\n REAL(DP) :: zt(20) = (/ &\n !\n ! 2-point formula\n -0.577350269189626E0_DP, & ! = zt( 1 + ngs(2) )\n 0.577350269189626E0_DP, & ! = zt( 2 + ngs(2) )\n !\n ! 3-point formula\n -0.774596669241483E0_DP, & ! = zt( 1 + ngs(3) )\n 0.000000000000000E0_DP, & ! = zt( 2 + ngs(3) )\n 0.774596669241483E0_DP, & ! = zt( 3 + ngs(3) )\n !\n ! 4-point formula\n -0.861136311594053E0_DP, & ! = zt( 1 + ngs(4) )\n -0.339981043584856E0_DP, & ! = zt( 2 + ngs(4) )\n 0.339981043584856E0_DP, & ! = zt( 3 + ngs(4) )\n 0.861136311594053E0_DP, & ! = zt( 4 + ngs(4) )\n !\n ! 5-point formula\n -0.906179845938664E0_DP, & ! = zt( 1 + ngs(5) )\n -0.538469310105683E0_DP, & ! = zt( 2 + ngs(5) )\n 0.000000000000000E0_DP, & ! = zt( 3 + ngs(5) )\n 0.538469310105683E0_DP, & ! = zt( 4 + ngs(5) )\n 0.906179845938664E0_DP, & ! = zt( 5 + ngs(5) )\n !\n ! 6-point formula\n -0.932469514203152E0_DP, & ! = zt( 1 + ngs(6) )\n -0.661209386466265E0_DP, & ! = zt( 2 + ngs(6) )\n -0.238619186083197E0_DP, & ! = zt( 3 + ngs(6) )\n 0.238619186083197E0_DP, & ! = zt( 4 + ngs(6) )\n 0.661209386466265E0_DP, & ! = zt( 5 + ngs(6) )\n 0.932469514203152E0_DP & ! = zt( 6 + ngs(6) )\n /)\n\n ! Weights to multiply to the function values at the integration points\n REAL(DP) :: wt(20) =(/ &\n ! 2-point formula\n 0.100000000000000E1_DP, & ! = wt( 1 + ngs(2) )\n 0.100000000000000E1_DP, & ! = wt( 2 + ngs(2) )\n !\n ! 3-point formula\n 0.555555555555556E0_DP, & ! = wt( 1 + ngs(3) )\n 0.888888888888889E0_DP, & ! = wt( 2 + ngs(3) )\n 0.555555555555556E0_DP, & ! = wt( 3 + ngs(3) )\n !\n ! 4-point formula\n 0.347854845137454E0_DP, & ! = wt( 1 + ngs(4) )\n 0.652145154862546E0_DP, & ! = wt( 2 + ngs(4) )\n 0.652145154862546E0_DP, & ! = wt( 3 + ngs(4) )\n 0.347854845137454E0_DP, & ! = wt( 4 + ngs(4) )\n !\n ! 5-point formula\n 0.236926885056189E0_DP, & ! = wt( 1 + ngs(5) )\n 0.478628670499366E0_DP, & ! = wt( 2 + ngs(5) )\n 0.568888888888889E0_DP, & ! = wt( 3 + ngs(5) )\n 0.478628670499366E0_DP, & ! = wt( 4 + ngs(5) )\n 0.236926885056189E0_DP, & ! = wt( 5 + ngs(5) )\n !\n ! 6-point formula\n 0.171324492379170E0_DP, & ! = wt( 1 + ngs(6) )\n 0.360761573048139E0_DP, & ! = wt( 2 + ngs(6) )\n 0.467913934572691E0_DP, & ! = wt( 3 + ngs(6) )\n 0.467913934572691E0_DP, & ! = wt( 4 + ngs(6) )\n 0.360761573048139E0_DP, & ! = wt( 5 + ngs(6) )\n 0.171324492379170E0_DP & ! = wt( 6 + ngs(6) )\n /)\n\nEND MODULE Gauss\n", "meta": {"hexsha": "dd10ee4400121284f9521e719837fdf1c7575fa9", "size": 3255, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Gauss.f90", "max_stars_repo_name": "anducnguyen/ferritas_e", "max_stars_repo_head_hexsha": "e3273c5513d6f22b060b4ea9034022b07785746f", "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": "Gauss.f90", "max_issues_repo_name": "anducnguyen/ferritas_e", "max_issues_repo_head_hexsha": "e3273c5513d6f22b060b4ea9034022b07785746f", "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": "Gauss.f90", "max_forks_repo_name": "anducnguyen/ferritas_e", "max_forks_repo_head_hexsha": "e3273c5513d6f22b060b4ea9034022b07785746f", "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": 37.8488372093, "max_line_length": 78, "alphanum_fraction": 0.490015361, "num_tokens": 1454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122696813394, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.8063951221366875}} {"text": "! function curl3D1(f1,f2,f3,dx1,dx2,dx3)\n!\n! !------------------------------------------------------------\n! !-------COMPUTE A 3D CURL, X1 COMPONENT. IT IS EXPECTED THAT \n! !-------GHOST CELLS WILL HAVE BEEN TRIMMED FROM ARRAYS BEFORE\n! !-------THEY ARE PASSED INTO THIS ROUTINE. DX(I) IS PRESUMED\n! !-------TO BE THE *BACKWARD* DIFFERENCE AT POINT I.\n! !-------\n! !-------THE F1 COMPONENT AND DIFF COULD BE OMITTED.\n! !------------------------------------------------------------\n!\n! real(wp), dimension(:,:,:), intent(in) :: f1,f2,f3\n! real(wp), dimension(1:size(f1,1)), intent(in) :: dx1\n! real(wp), dimension(1:size(f1,2)), intent(in) :: dx2\n! real(wp), dimension(1:size(f1,3)), intent(in) :: dx3\n!\n! integer :: ix1,ix2,ix3,lx1,lx2,lx3\n!\n! real(wp), dimension(1:size(f1,1),1:size(f1,2),1:size(f1,3)) :: curl3D1\n!\n! lx1=size(f1,1)\n! lx2=size(f1,2)\n! lx3=size(f1,3)\n!\n! if (lx2>1) then\n! do ix3=1,lx3\n! do ix1=1,lx1\n! curl3D1(ix1,1,ix3)=(f3(ix1,2,ix3)-f3(ix1,1,ix3))/dx2(2) !fwd diff\n! curl3D1(ix1,2:lx2-1,ix3)=(f3(ix1,3:lx2,ix3)-f3(ix1,1:lx2-2,ix3)) &\n! /(dx2(3:lx2)+dx2(2:lx2-1))\n! curl3D1(ix1,lx2,ix3)=(f3(ix1,lx2,ix3)-f3(ix1,lx2-1,ix3))/dx2(lx2) !bwd diff\n! end do\n! end do\n! else\n! curl3D1=0d0\n! end if\n!\n! do ix2=1,lx2\n! do ix1=1,lx1\n! curl3D1(ix1,ix2,1)=curl3D1(ix1,ix2,1)-(f2(ix1,ix2,2)-f2(ix1,ix2,1))/dx3(2)\n! curl3D1(ix1,ix2,2:lx3-1)=curl3D1(ix1,ix2,2:lx3-1)- &\n! (f2(ix1,ix2,3:lx3)-f2(ix1,ix2,1:lx3-2)) &\n! /(dx3(3:lx3)+dx3(2:lx3-1))\n! curl3D1(ix1,ix2,lx3)=curl3D1(ix1,ix2,lx3)-(f2(ix1,ix2,lx3)-f2(ix1,ix2,lx3-1))/dx3(lx3)\n! end do\n! end do\n!\n! end function curl3D1\n!\n!\n! function curl3D2(f1,f2,f3,dx1,dx2,dx3)\n!\n! !------------------------------------------------------------\n! !-------COMPUTE A 3D CURL, X2 COMPONENT. IT IS EXPECTED THAT \n! !-------GHOST CELLS WILL HAVE BEEN TRIMMED FROM ARRAYS BEFORE\n! !-------THEY ARE PASSED INTO THIS ROUTINE. DX(I) IS PRESUMED\n! !-------TO BE THE *BACKWARD* DIFFERENCE AT POINT I\n! !-------\n! !-------THE F2 COMPONENT AND DIFF COULD BE OMITTED.\n! !-------ARE THE SIGNS RIGHT?\n! !------------------------------------------------------------\n!\n! real(wp), dimension(:,:,:), intent(in) :: f1,f2,f3\n! real(wp), dimension(1:size(f1,1)), intent(in) :: dx1\n! real(wp), dimension(1:size(f1,2)), intent(in) :: dx2\n! real(wp), dimension(1:size(f1,3)), intent(in) :: dx3\n!\n! integer :: ix1,ix2,ix3,lx1,lx2,lx3\n!\n! real(wp), dimension(1:size(f1,1),1:size(f1,2),1:size(f1,3)) :: curl3D2\n!\n! lx1=size(f1,1)\n! lx2=size(f1,2)\n! lx3=size(f1,3)\n!\n! do ix2=1,lx2\n! do ix1=1,lx1\n! curl3D2(1,ix2,ix3)=(f3(2,ix2,ix3)-f3(1,ix2,ix3))/dx1(2) !fwd diff\n! curl3D2(2:lx1-1,ix2,ix3)=(f3(3:lx1,ix2,ix3)-f3(1:lx1-2,ix2,ix3)) &\n! /(dx1(3:lx1)+dx1(2:lx1-1))\n! curl3D2(lx1,ix2,ix3)=(f3(lx1,ix2,ix3)-f3(lx1-1,ix2,ix3))/dx1(lx1) !bwd diff\n! end do\n! end do\n!\n! do ix2=1,lx2\n! do ix1=1,lx1\n! curl3D2(ix1,ix2,1)=curl3D2(ix1,ix2,1)-(f1(ix1,ix2,2)-f1(ix1,ix2,1))/dx3(2)\n! curl3D2(ix1,ix2,2:lx3-1)=curl3D2(ix1,ix2,2:lx3-1)- &\n! (f1(ix1,ix2,3:lx3)-f1(ix1,ix2,1:lx3-2)) &\n! /(dx3(3:lx3)+dx3(2:lx3-1))\n! curl3D2(ix1,ix2,lx3)=curl3D2(ix1,ix2,lx3)-(f1(ix1,ix2,lx3)-f1(ix1,ix2,lx3-1))/dx3(lx3)\n! end do\n! end do\n!\n! end function curl3D2\n!\n!\n! function curl3D3(f1,f2,f3,dx1,dx2,dx3)\n!\n! !------------------------------------------------------------\n! !-------COMPUTE A 3D CURL, X3 COMPONENT. IT IS EXPECTED THAT \n! !-------GHOST CELLS WILL HAVE BEEN TRIMMED FROM ARRAYS BEFORE\n! !-------THEY ARE PASSED INTO THIS ROUTINE. DX(I) IS PRESUMED\n! !-------TO BE THE *BACKWARD* DIFFERENCE AT POINT I\n! !-------\n! !-------THE F3 COMPONENT AND DIFF COULD BE OMITTED.\n! !------------------------------------------------------------\n!\n! real(wp), dimension(:,:,:), intent(in) :: f1,f2,f3\n! real(wp), dimension(1:size(f1,1)), intent(in) :: dx1\n! real(wp), dimension(1:size(f1,2)), intent(in) :: dx2\n! real(wp), dimension(1:size(f1,3)), intent(in) :: dx3\n!\n! integer :: ix1,ix2,ix3,lx1,lx2,lx3\n!\n! real(wp), dimension(1:size(f1,1),1:size(f1,2),1:size(f1,3)) :: curl3D3\n!\n! lx1=size(f1,1)\n! lx2=size(f1,2)\n! lx3=size(f1,3)\n!\n! do ix2=1,lx2\n! do ix1=1,lx1\n! curl3D3(1,ix2,ix3)=(f2(2,ix2,ix3)-f2(1,ix2,ix3))/dx1(2) !fwd diff\n! curl3D3(2:lx1-1,ix2,ix3)=(f2(3:lx1,ix2,ix3)-f2(1:lx1-2,ix2,ix3)) &\n! /(dx1(3:lx1)+dx1(2:lx1-1))\n! curl3D3(lx1,ix2,ix3)=(f2(lx1,ix2,ix3)-f2(lx1-1,ix2,ix3))/dx1(lx1) !bwd diff\n! end do\n! end do\n!\n! if (lx2>1) then\n! do ix3=1,lx3\n! do ix1=1,lx1\n! curl3D3(ix1,1,ix3)=curl3D3(ix1,1,ix3)-(f1(ix1,2,ix3)-f1(ix1,1,ix3))/dx2(2) !fwd diff\n! curl3D3(ix1,2:lx2-1,ix3)=curl3D3(ix1,2:lx2-1,ix3)- &\n! (f1(ix1,3:lx2,ix3)-f1(ix1,1:lx2-2,ix3)) &\n! /(dx2(3:lx2)+dx2(2:lx2-1))\n! curl3D3(ix1,lx2,ix3)=curl3D3(ix1,lx2,ix3)-(f1(ix1,lx2,ix3)-f1(ix1,lx2-1,ix3))/dx2(lx2) !bwd diff\n! end do\n! end do\n! end if\n!\n! end function curl3D3\n", "meta": {"hexsha": "9709fe908fb8139068989afd1f6c8376b5eec232", "size": 5502, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "archive/calculus.f90", "max_stars_repo_name": "gemini3d/archive", "max_stars_repo_head_hexsha": "bdb0bb923dc285dec0b1edeaf68f800dff073fec", "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": "archive/calculus.f90", "max_issues_repo_name": "gemini3d/archive", "max_issues_repo_head_hexsha": "bdb0bb923dc285dec0b1edeaf68f800dff073fec", "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": "archive/calculus.f90", "max_forks_repo_name": "gemini3d/archive", "max_forks_repo_head_hexsha": "bdb0bb923dc285dec0b1edeaf68f800dff073fec", "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": 38.2083333333, "max_line_length": 110, "alphanum_fraction": 0.4883678662, "num_tokens": 2338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361742, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.8062446586581716}} {"text": " PROGRAM mean_R\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,WS_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,WS\n\n!!!=======================================================================================\n!!!======================================================================================= \n OPEN(unit=11,file='average.dat')\n OPEN(unit=12,file='average_av.dat')\n OPEN(unit=13,file='Ra_dev.dat')\n OPEN(unit=14,file='Rd_dev.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),WS(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 WS_av=WS_av+abs(WS(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 ; WS_av=WS_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,1./Kab,Ra_av,Rb_av,Rd_av,R_av,R_av-R_dev,R_av+R_dev,WS_av\n WRITE(13,*)Kad,1./Kab,Ra_av,Ra_av-Ra_dev,Ra_av+Ra_dev,Rb_av,Rb_av-Rb_dev,Rb_av+Rb_dev\n WRITE(14,*)Kad,1./Kab,Rd_av,Rd_av-Rd_dev,Rd_av+Rd_dev\n\n CLOSE(11)\n CLOSE(12)\n CLOSE(13)\n CLOSE(14)\n \n END PROGRAM mean_R\n\n", "meta": {"hexsha": "83c0c0b2c912276e390fb743855f2153fa140b29", "size": 1667, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/0.0Kab/0mean_R.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/0mean_R.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/0mean_R.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": 24.5147058824, "max_line_length": 91, "alphanum_fraction": 0.5374925015, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.8062276937301596}} {"text": "! Objetivo: Reproduzir o gráfico da funcao gama\n\nPROGRAM grafico_gama\n\tUSE nrtype\n\tUSE nrutil\n\tUSE nr, ONLY: gammln\n\tIMPLICIT none\n\tINTEGER :: cont_pontos, variacao_x_positivo \n\tINTEGER, PARAMETER :: saida_gama = 9, total_pontos = 1000\n\tINTEGER, PARAMETER :: x_positivo = total_pontos/2\n\tREAL :: x, pi_x, x_mais_1\n\tREAL, PARAMETER :: x_inicial = -5.25, x_final = 5.25\n\tREAL, PARAMETER :: incremento_x=(x_final-x_inicial)/(total_pontos)\n\tREAL, DIMENSION(-x_positivo:x_positivo) :: funcao_gama\n\n\tx = 0.0\n\tDO variacao_x_positivo = 1, x_positivo\n\t\tx = x+incremento_x\n\t\tx_mais_1 = 1.0+x\n! funcao gama para abscissas positivas\n\t\tfuncao_gama(variacao_x_positivo) = exp(gammln(x_mais_1))\n\t\tpi_x = pi*x\n! Pela formula de reflexao para abscissas negativas\n\t\tfuncao_gama (-variacao_x_positivo) = pi_x/(funcao_gama&\n\t\t\t\t\t(variacao_x_positivo)*sin(pi_x))\n\tEND DO\n\tx = x_inicial\n! Quando o argumento for igual a zero\n\tfuncao_gama(0) = 1.0\n\tOPEN(unit=saida_gama, file=\"dados_gama.dat\")\n\tDO cont_pontos = -x_positivo, x_positivo\n\t\tWRITE(saida_gama,fmt=*) x, funcao_gama(cont_pontos)\n\t\tx = x+incremento_x\n\tEND DO\n\tCLOSE(unit=saida_gama) \nEND PROGRAM grafico_gama\n", "meta": {"hexsha": "a7c799b2ae817eadabcd702190a955bcbfe7e064", "size": 1147, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "graf_gama.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": "graf_gama.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": "graf_gama.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.0, "max_line_length": 67, "alphanum_fraction": 0.7471665214, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8062276903126887}} {"text": "FUNCTION polyarea(x, y, nb) RESULT(fn_val)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2000-07-04 Time: 12:24:06\r\n\r\nIMPLICIT NONE\r\n\r\nREAL, INTENT(IN) :: x(:)\r\nREAL, INTENT(IN) :: y(:)\r\nINTEGER, INTENT(IN) :: nb\r\nREAL :: fn_val\r\n\r\n!*****************************************************************\r\n\r\n! GIVEN A SEQUENCE OF NB POINTS (X(I),Y(I)), polyarea COMPUTES THE AREA\r\n! BOUNDED BY THE CLOSED POLYGONAL CURVE WHICH PASSES THROUGH THE POINTS IN\r\n! THE ORDER THAT THEY ARE INDEXED. THE FINAL POINT OF THE CURVE IS ASSUMED\r\n! TO BE THE FIRST POINT GIVEN. THEREFORE, IT NEED NOT BE LISTED AT THE END\r\n! OF X AND Y. THE CURVE IS NOT REQUIRED TO BE SIMPLE. e.g. It may cross over\r\n! itself.\r\n\r\n!*****************************************************************\r\n\r\nINTEGER :: i, n, nm1\r\nREAL :: a\r\n\r\nn = nb\r\nIF (x(1) == x(n) .AND. y(1) == y(n)) n = n - 1\r\n\r\nSELECT CASE (n)\r\n CASE (:2)\r\n fn_val = 0.0\r\n\r\n CASE (3)\r\n fn_val= 0.5*((x(2) - x(1))*(y(3) - y(1)) - (x(3) - x(1))*(y(2) - y(1)))\r\n\r\n CASE DEFAULT\r\n nm1 = n - 1\r\n a = x(1)*(y(2) - y(n)) + x(n)*(y(1) - y(nm1))\r\n DO i = 2, nm1\r\n a = a + x(i)*(y(i+1) - y(i-1))\r\n END DO\r\n fn_val = 0.5*a\r\nEND SELECT\r\n\r\nRETURN\r\nEND FUNCTION polyarea\r\n", "meta": {"hexsha": "1c07ba63ebb29c4652bdff88fbe8640430d76dc4", "size": 1269, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/polyarea.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/polyarea.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/polyarea.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.4375, "max_line_length": 79, "alphanum_fraction": 0.4933018125, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.8059178688131459}} {"text": "\tFUNCTION PR_TMFC ( tmpf )\nC************************************************************************\nC* PR_TMFC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPC 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* TMPC = ( TMPF - 32 ) * 5 / 9\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMFC ( 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_TMFC\t\tREAL\t\tTemperature 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* J. Woytek/GSFC\t10/82\tOriginal source code\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************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC*\n\tPARAMETER\t( RPRM = 5. / 9. )\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpf ) ) THEN\n\t PR_TMFC = RMISSD\n\t ELSE\n\t PR_TMFC = ( tmpf - 32.0 ) * RPRM\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "bb2028451f0fce88400c29d579722c2105337b46", "size": 1117, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmfc.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/prtmfc.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/prtmfc.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.3947368421, "max_line_length": 73, "alphanum_fraction": 0.4270367055, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.8059040209263165}} {"text": "Program Cholesky_decomp\n! *************************************************!\n! LBH @ ULPGC 06/03/2014\n! Compute the Cholesky decomposition for a matrix A\n! after the attached\n! http://rosettacode.org/wiki/Cholesky_decomposition\n! note that the matrix A is complex since there might\n! be values, where the sqrt has complex solutions.\n! Here, only the real values are taken into account\n!*************************************************!\nimplicit none\n\nINTEGER, PARAMETER :: m=3 !rows\nINTEGER, PARAMETER :: n=3 !cols\nCOMPLEX, DIMENSION(m,n) :: A\nREAL, DIMENSION(m,n) :: L\nREAL :: sum1, sum2\nINTEGER i,j,k\n\n! Assign values to the matrix\nA(1,:)=(/ 25, 15, -5 /)\nA(2,:)=(/ 15, 18, 0 /)\nA(3,:)=(/ -5, 0, 11 /)\n! !!!!!!!!!!!another example!!!!!!!\n! A(1,:) = (/ 18, 22, 54, 42 /)\n! A(2,:) = (/ 22, 70, 86, 62 /)\n! A(3,:) = (/ 54, 86, 174, 134 /)\n! A(4,:) = (/ 42, 62, 134, 106 /)\n\n\n\n\n\n! Initialize values\nL(1,1)=real(sqrt(A(1,1)))\nL(2,1)=A(2,1)/L(1,1)\nL(2,2)=real(sqrt(A(2,2)-L(2,1)*L(2,1)))\nL(3,1)=A(3,1)/L(1,1)\n! for greater order than m,n=3 add initial row value\n! for instance if m,n=4 then add the following line\n! L(4,1)=A(4,1)/L(1,1)\n\n\n\n\n\ndo i=1,n\n do k=1,i\n sum1=0\n sum2=0\n do j=1,k-1\n if (i==k) then\n sum1=sum1+(L(k,j)*L(k,j))\n L(k,k)=real(sqrt(A(k,k)-sum1))\n elseif (i > k) then\n sum2=sum2+(L(i,j)*L(k,j))\n L(i,k)=(1/L(k,k))*(A(i,k)-sum2)\n else\n L(i,k)=0\n end if\n end do\n end do\nend do\n\n! write output\ndo i=1,m\n print \"(3(1X,F6.1))\",L(i,:)\nend do\n\nEnd program Cholesky_decomp\n", "meta": {"hexsha": "b8cda8d28158ad6d8924e7da4dc871ba58824a3e", "size": 1623, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Cholesky-decomposition/Fortran/cholesky-decomposition.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/Cholesky-decomposition/Fortran/cholesky-decomposition.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/Cholesky-decomposition/Fortran/cholesky-decomposition.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": 22.8591549296, "max_line_length": 53, "alphanum_fraction": 0.5077017868, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.8058610163256991}} {"text": "! for more info refer : https://www.tutorialspoint.com/fortran/fortran_operators\r\nprogram operators\r\n ! CTM: here i don't have used 'implicit none' keep that in mind if u use variables \r\n\r\n!Arithmetic Operators \r\n print *, \"Arithmetic Operators\";\r\n print *, \"2 + 20 = \", 2 + 20; \r\n print *, \"2 - 20 = \", 2 - 20; \r\n print *, \"2 * 20 = \", 2 * 20; \r\n print *, \"20 / 3 = \", 20 / 3;\r\n print *, \"mod(20, 3) = \", mod(20, 2); \r\n print *, \"2**20 = \", 2**10;\r\n \r\n!Relation\r\n print *, char(10) ! new line\r\n print *, \"Relational Operators\";\r\n print *, \"2 > 5 = \", 2 > 5;\r\n print *, \"2 >= 5 = \", 2 >= 5;\r\n print *, \"2 < 5 = \", 2 < 5;\r\n print *, \"2 <= 5 = \", 2 <= 5;\r\n print *, \"2 == 5 = \", 2 == 5;\r\n print *, \"2 /= 5 = \", 2 /= 5; ! '/=' its is not equal operator\r\n ! Alternate Method\r\n print *, char(10) ! new line\r\n print *, \"Relational Operators\";\r\n print *, \"2 .gt. 5 = \", 2 .gt. 5;\r\n print *, \"2 .ge. 5 = \", 2 .ge. 5;\r\n print *, \"2 .lt. 5 = \", 2 .lt. 5;\r\n print *, \"2 .le. 5 = \", 2 .le. 5;\r\n print *, \"2 .eq. 5 = \", 2 .eq. 5;\r\n print *, \"2 .ne. 5 = \", 2 .ne. 5;\r\n\r\n\r\n!boolean\r\n print *, char(10) ! new line\r\n print *, \"Boolean Values\";\r\n print *, \".true. = \", .true.;\r\n print *, \".false. = \", .false.;\r\n\r\n\r\n!logical\r\n print *, char(10) ! new line\r\n print *, \"Logical Operators \";\r\n print *, \".true..and..false.= \", .true..and..false.; ! General Syntax (exp).and.(exp) \r\n print *, \".true..or..false. = \", .true..or..false.;\r\n print *, \".not..true. = \", .not..true.; \r\n print *, \"(5<50).eqv.(10<90)= \", (5 < 50).eqv.(10 < 90); ! General Syntax (exp).eqv.(eqv) ! NOTE : its not .e q.\r\n print *, \"(5<50).neqv.(10<90)= \", (5 < 50).neqv.(10 < 90); ! General Syntax (exp).eqv.(eqv) ! NOTE : its not .eq.\r\n \r\nend program operators", "meta": {"hexsha": "6d8f0f27b3e8171870de8fbf3dfcc1b219e428f0", "size": 1882, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/Practice/operators.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/operators.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/operators.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": 37.64, "max_line_length": 127, "alphanum_fraction": 0.4622741764, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.8058420978166968}} {"text": "program P3\n ! integrate exp(-x) from [-1,+1] by Gaussian algorithm\n implicit none\n integer :: i,j\n real*4, dimension(:), allocatable :: x,w\n integer, dimension(2) :: n\n real*4 :: f_n,f_a,x0=-1,xf=1\n real*4, external :: f\n\n n = (/4,8/)\n f_a = -exp(x0)+exp(xf)\n \n do i = 1,2\n allocate(x(n(i)),w(n(i)))\n call gauleg(x0,xf,x,w,n(i))\n\n f_n = 0\n do j = 1,n(i)\n f_n = f_n + w(j)*f(x(j))\n enddo\n \n print *,n(i),f_n-f_a,(f_n-f_a)/f_a\n deallocate(x,w)\n enddo\n \nend program P3\n\nreal*4 function f(x)\n implicit none\n real*4, intent(in) :: x\n f=exp(-x)\nend function f\n", "meta": {"hexsha": "9358bde899ccc4ec13550dc282f8c7d86ea935b9", "size": 610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HW2/P3.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/P3.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/P3.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": 18.4848484848, "max_line_length": 57, "alphanum_fraction": 0.5442622951, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.8058228808391011}} {"text": " program demo_random_number\n use, intrinsic :: iso_fortran_env, only : dp=>real64\n implicit none\n integer :: i, n, first,last, rand_int\n integer,allocatable :: count(:)\n real(kind=dp) :: rand_val\n call random_seed() ! initialize random number sequence\n ! generate a lot of random integers from 1 to 10 and count them.\n first=1\n last=10\n allocate(count(last-first+1))\n ! To have a discrete uniform distribution on the integers\n ! [first, first+1, ..., last-1, last] carve the continuous\n ! distribution up into last+1-first equal sized chunks,\n ! mapping each chunk to an integer. One way is:\n ! call random_number(rand_val)\n ! choose one from last-first+1 integers\n ! rand_int = first + FLOOR((last+1-first)*rand_val)\n count=0\n ! generate a lot of random integers from 1 to 10 and count them.\n ! with a large number of values you should get about the same\n ! number of each value\n do i=1,100000000\n call random_number(rand_val)\n rand_int=first+floor((last+1-first)*rand_val)\n if(rand_int.ge.first.and.rand_int.le.last)then\n count(rand_int)=count(rand_int)+1\n else\n write(*,*)rand_int,' is out of range'\n endif\n enddo\n write(*,'(i0.3,1x,i12)')(i,count(i),i=1,size(count))\n end program demo_random_number\n", "meta": {"hexsha": "151ae5e5537ebfd40ec8f82a8ed2f9c927372d02", "size": 1432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/random_number.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/random_number.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/random_number.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": 42.1176470588, "max_line_length": 71, "alphanum_fraction": 0.6180167598, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.8056861420938195}} {"text": "!==========================================\n! pi_calc.f90\n! Author: Devansh Shukla\n!------------------------------------------\nprogram pi_estimate\n\n implicit none\n ! Defining the variables\n real*8 :: x=0.0, y=0.0, pi=0.0, dist=0.0\n integer :: i=0, hits=0, n=0\n character(len=*), parameter :: fmt = \"(I4 F10.3 F10.3)\"\n\n ! Opening the data file\n open(unit=8, file=\"random_no.dat\")\n\n ! Getting input from the user for total no. of darts\n print *, \"Enter the total no. of darts (n)\"\n read *, n\n print *, \"------------\"\n\n ! Do-loop for computing\n do i=0, n, 1\n ! compute the random numbers\n call RANDOM_NUMBER(x)\n call RANDOM_NUMBER(y)\n ! compute the distance\n dist = sqrt(x**2 + y**2)\n ! Write the computed random numbers to the data file\n write (8,fmt) i, x, y\n ! Check if the distance is less than or equal to one\n ! if yes then increment `hits` by 1\n if (dist .le. 1.0) then\n hits = hits + 1\n endif\n enddo\n\n ! Compute the value of `pi` and write it to `stdout` for the user\n pi = 4.0 * hits/n\n print \"(xA,F6.4)\", \"pi=\", pi\n print *, \"------------\"\n\n ! Close the data file\n close(8)\n\nend program pi_estimate\n", "meta": {"hexsha": "e392f294db580c472d7de875a4736771d6ac411e", "size": 1254, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "M10/pi_calc.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": "M10/pi_calc.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": "M10/pi_calc.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": 27.2608695652, "max_line_length": 69, "alphanum_fraction": 0.5215311005, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.8056861404089902}} {"text": "! Routine for linear approximation\r\n! Igor Lopes, February 2015\r\nSUBROUTINE POLYLIN(NPOINT,X,F)\r\n IMPLICIT NONE\r\n ! Arguments\r\n INTEGER NPOINT\r\n REAL(8) :: XMIN, FMIN\r\n REAL(8),DIMENSION(4) :: X , F\r\n ! Locals\r\n REAL(8) :: A0,A1\r\n ! Begin algorithm\r\n IF(NPOINT.EQ.1)THEN\r\n A1=F(2)\r\n A0=F(1)-F(2)*X(1)\r\n ELSEIF(NPOINT.EQ.2)THEN\r\n A1=(F(2)-F(1))/(X(2)-X(1))\r\n A0=F(1)-A1*X(1)\r\n ELSE\r\n WRITE(*,*)'Wrong number of input points in POLYLIN'\r\n GOTO 99\r\n ENDIF\r\n WRITE(*,*)'Approximation coefficients:'\r\n WRITE(*,*)'a0=',A0\r\n WRITE(*,*)'a1=',A1\r\n WRITE(11,*)'Approximation coefficients:'\r\n WRITE(11,*)'a0=',A0\r\n WRITE(11,*)'a1=',A1\r\n99 CONTINUE \r\nEND SUBROUTINE", "meta": {"hexsha": "c84d328b5ff82c839a42c7ac0612b9a23cbc8637", "size": 752, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/polynomial_approx/polylin.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/polynomial_approx/polylin.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/polynomial_approx/polylin.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": 25.9310344828, "max_line_length": 60, "alphanum_fraction": 0.545212766, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.9032942164664239, "lm_q1q2_score": 0.8055677595249571}} {"text": "module calculates\nimplicit none\ncontains\n\n! factorial:\n\ninteger function fact(n)\n integer, intent(in) :: n\n integer :: i\n\n fact = 1\n do i = 2, n\n fact = fact * i\n! write(*,*) \" i \", i, \"fact(n)\", fact\n end do\n write(*,*) \"n \", n, \"fact(n)\", fact\nend function fact\n\n!rounding\n\nreal(kind=8) function rounded(a)\n real(kind=8), intent(in) :: a\n\n rounded = dble(nint(a*(10**5)))/(10**5)\n write(*,*) \" rounded \", a, rounded\nend function rounded\n\n!taylor series:\n\nsubroutine taylor (x, n, exp_x)\n real(kind=8), intent(in) :: x\n integer, intent(in) :: n\n integer :: i\n real(kind=8), intent(out) :: exp_x\n real(kind=8) :: test\n\n exp_x = 1\n\n do i = 1, n-1\n exp_x = rounded(exp_x) + rounded(rounded(x**i)/rounded(dble(fact(i))))\n test = rounded(rounded(x**i)/rounded(dble(fact(i))))\n write (*,*) \"term \", i+1, \"exp(-2) \", test, \"result \", exp_x\n end do\n exp_x = rounded(exp_x)\nend subroutine taylor\n\nend module calculates\n", "meta": {"hexsha": "4c72a488c5e94c5685d57847f2da3e48984154c0", "size": 1037, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW1/ex6/module.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/ex6/module.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/ex6/module.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": 21.6041666667, "max_line_length": 76, "alphanum_fraction": 0.5506268081, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338090839607, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.8053999158574118}} {"text": "module quadrature_module\n\n use polynomial_module\n implicit none\n\n contains\n\n!===================================================================\nsubroutine trapzpointsandweights(x,w,np)\n\t\n\treal*8,allocatable,intent(out) :: w(:)\n\treal*8,allocatable,intent(out) :: x(:)\n\n\tinteger,intent(out) :: np\n\treal*8 :: dx\n\tinteger :: i\n\n\tnp=10 !for now\n\n\tdx=2.d0/(np-1)\n\n\tallocate(w(np))\n\tallocate(x(np))\n\n\tw(1)=0.5*dx\n\tx(1)=-1.0\n\n\tw(np)=0.5*dx\n\tx(np)=1.0\n\n\tdo i=2,np-1\n\t\tw(i)=dx\n\t\tx(i)=-1.d0+(i-1)*dx\n\tenddo\n\t\nend subroutine trapzpointsandweights\n!===================================================================\nsubroutine gausspointsandweights(x,w,npoints)\n\n\t\tinteger,intent(in) :: npoints\n\t\treal*8, allocatable, intent(out) :: w(:)\n\t\treal*8, allocatable, intent(out) :: x(:)\n\n\t\tallocate(w(npoints))\n\t\tallocate(x(npoints))\n\n\t\tif(npoints .eq. 1) then\n\t\t\tw(1)=2.0\n\t\t\tx(1)=0.0\n\t\tendif\n\n\t\tif(npoints .eq. 2) then\n\t\t\tw(1)=1.0\n\t\t\tw(2)=1.0\n\n\t\t\tx(1)=-1.0/sqrt(3.0)\n\t\t\tx(2)=1.0/sqrt(3.0)\n\t\tendif\n\n\t\tif(npoints .eq. 3) then\n\t\t\tw(1)=5.0/9.0\n\t\t\tw(2)=8.0/9.0\n\t\t\tw(3)=5.0/9.0\n\n\t\t\tx(1)=-sqrt(3.0/5.0)\n\t\t\tx(2)=0.0\n\t\t\tx(3)=sqrt(3.0/5.0)\n\t\tendif\n\n\t\tif(npoints .eq. 4) then\n\t\t\tw(1) = (18.0-sqrt(30.0))/36.0\n\t\t\tw(2) = (18.0+sqrt(30.0))/36.0\n\t\t\tw(3) = (18.0+sqrt(30.0))/36.0\n\t\t\tw(4) = (18.0-sqrt(30.0))/36.0\n\n\t\t\tx(1) = -sqrt((3.0+2.0*sqrt(6.0/5.0))/7.0)\n\t\t\tx(2) = -sqrt((3.0-2.0*sqrt(6.0/5.0))/7.0)\n\t\t\tx(3) = sqrt((3.0-2.0*sqrt(6.0/5.0))/7.0)\n\t\t\tx(4) = sqrt((3.0+2.0*sqrt(6.0/5.0))/7.0)\n\t\tendif\n\nend subroutine gausspointsandweights\n!===================================================================\nsubroutine gll_gen(x,w,N)\n\n integer, intent(in) :: N\n real*8,allocatable, intent(out) :: x(:),w(:)\n\n real*8 :: dleg(N+1)\n real*8 :: pi,tol,x_it,xold\n integer :: maxit,N1,i,j,k\n\n allocate(x(N+1))\n allocate(w(N+1))\n\n pi = acos(-1.)\n\n tol = 1d-15\n\n N1 = N+1\n\n maxit = 1000 ! max iterations for newton-raphson\n \n x(1) = -1.d0\n x(N1) = 1.d0\n \n do i = 1, N+1\n\n x_it = -cos(pi * float(i-1) / N) ! initial guess - chebyshev points\n\n do j = 1, maxit \n\n \t xold = x_it\n dleg(1) = 1.d0\n dleg(2) = x_it\n\n\t do k = 2,N \n\n dleg(k+1) = ( (2.d0*float(k) - 1.d0) * dleg(k) * x_it &\n - (float(k)-1.d0)*dleg(k-1) ) / float(k)\n \n enddo\n\n x_it = x_it - ( x_it * dleg(N1) - dleg(N) ) / &\n (float(N1) * dleg(N1) ) \n\n if (abs(x_it - xold) .lt. tol) goto 10\n\n enddo\n write(*,*) 'max itertions reached'\n10 continue\n\n x(i) = x_it\n w(i) = 2.d0 / (float(N * N1) * dleg(N1)**2 )\n\n enddo\n\n return\n\nend subroutine gll_gen\n!===================================================================\n subroutine gl_gen(x,w,n)\n integer n\n double precision x1,x2\n double precision eps\n parameter (eps=3.d-14)\n integer i,j,m\n double precision p1,p2,p3,pp,xl,xm,z,z1\n real*8,allocatable :: x(:),w(:)\n\n allocate(x(n))\n allocate(w(n))\n\n m=(n+1)/2\n\n x1 = -1.d0\n x2 = +1.d0\n\n xm=0.5d0*(x2+x1)\n xl=0.5d0*(x2-x1)\n do 12 i=1,m\n z=cos(3.141592653589793d0*(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)goto 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!===================================================================\nsubroutine globattopointsandweights(x,w,npoints)\n\n\t\treal*8,allocatable,intent(out) :: w(:),x(:)\n\t\tinteger, intent(in) :: npoints\n\n\t\tallocate(w(npoints))\n\t\tallocate(x(npoints))\n\n\t\tif(npoints .eq. 2) then\n\t\t\tw(1)=1.0\n\t\t\tw(2)=1.0\n\n\t\t\tx(1)=-1.0\n\t\t\tx(2)=1.0\n\t\tendif\n\n\t\tif(npoints .eq. 3) then\n\n\t\t\tw(1)=1.0/3.0\n\t\t\tw(2)=4.0/3.0\n\t\t\tw(3)=1.0/3.0\n\n\t\t\tx(1)=-1.0\n\t\t\tx(2)=0.0\n\t\t\tx(3)=1.0\n\t\tendif\n\n\t\tif(npoints .eq. 4) then\n\n\t\t\tw(1)=1.0/6.0\n\t\t\tw(2)=5.0/6.0\n\t\t\tw(3)=5.0/6.0\n\t\t\tw(4)=1.0/6.0\n\n\t\t\tx(1)=-1.0\n\t\t\tx(2)=-sqrt(1.0/5.0)\n\t\t\tx(3)=sqrt(1.0/5.0)\n\t\t\tx(4)=1.0\n\t\tendif\n\n\t\tif(npoints .eq. 5) then\n\n\t\t\tw(1)=1.0/10.0\n\t\t\tw(2)=49.0/90.0\n\t\t\tw(3)=32.0/45.0\n\t\t\tw(4)=49.0/90.0\n\t\t\tw(5)=1.0/10.0\n\n\t\t\tx(1)=-1.0\n\t\t\tx(2)=-sqrt(3.0/7.0)\n\t\t\tx(3)=0.0\n\t\t\tx(4)=sqrt(3.0/7.0)\n\t\t\tx(5)=1.0\n\t\tendif\n\n\nend subroutine globattopointsandweights\n!===================================================================\nsubroutine getuniformlagrangepoints(n,x)\n\n\t\tinteger :: n\n\t\treal*8 :: x(:)\n\n\t\tinteger :: i\n\t\treal*8 :: delx\n\t\treal*8 :: xmin,xmax\n\n\t\txmin = -1.d0\n\t\txmax = 1.d0\n\t\tdelx= (xmax-xmin)/n\n\n\t\tdo i=1,n+1\n\t\t\tx(i)=xmin+(i-1)*delx\n\t\tenddo\n\nend subroutine getuniformlagrangepoints\n!===================================================================\nsubroutine convolvetrapz(p1,p2,a,b,npoints,answer)\n\n\t type(polynomial), intent(in) :: p1,p2\n\t real*8, intent(in) :: a,b\n\t integer, intent(in) :: npoints\n\t real*8 , intent(out) :: answer\n\n\t integer :: i\n\t real*8 :: delx,integval\n\t real*8 :: h1,h2\n\n\t delx=(b-a)/(npoints-1)\n\t integval=0.0\n\n\t do i=1,npoints-1\n\n\t \th1 = polyfindval(p1,a+(i-1)*delx)*polyfindval(p2,a+(i-1)*delx)\n\t\th2 = polyfindval(p1,a+i*delx)*polyfindval(p2,a+i*delx)\n\n\t\tintegval = integval + 0.5*delx*(h1+h2)\n\n\t enddo\n\n\t answer=integval\n\nend subroutine convolvetrapz\n!===================================================================\n\nend module quadrature_module\n", "meta": {"hexsha": "f6331aa514b37881151a2851e029b26ba127b7b7", "size": 5637, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pretreatment_model/src/quadrature.f90", "max_stars_repo_name": "NREL/VirtualEngineering", "max_stars_repo_head_hexsha": "f23f409132bc7965334db1e29d83502001ec4e09", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-23T21:33:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T08:06:24.000Z", "max_issues_repo_path": "pretreatment_model/src/quadrature.f90", "max_issues_repo_name": "NREL/VirtualEngineering", "max_issues_repo_head_hexsha": "f23f409132bc7965334db1e29d83502001ec4e09", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T19:10:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T22:24:34.000Z", "max_forks_repo_path": "pretreatment_model/src/quadrature.f90", "max_forks_repo_name": "NREL/VirtualEngineering", "max_forks_repo_head_hexsha": "f23f409132bc7965334db1e29d83502001ec4e09", "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": 19.5051903114, "max_line_length": 75, "alphanum_fraction": 0.4660280291, "num_tokens": 2249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.8053947987827443}} {"text": " SUBROUTINE chebft(a,b,c,n,func)\r\n INTEGER n,NMAX\r\n REAL a,b,c(n),func,PI\r\n EXTERNAL func\r\n PARAMETER (NMAX=50, PI=3.141592653589793d0)\r\n INTEGER j,k\r\n REAL bma,bpa,fac,y,f(NMAX)\r\n DOUBLE PRECISION sum\r\n bma=0.5*(b-a)\r\n bpa=0.5*(b+a)\r\n do 11 k=1,n\r\n y=cos(PI*(k-0.5)/n)\r\n f(k)=func(y*bma+bpa)\r\n11 continue\r\n fac=2./n\r\n do 13 j=1,n\r\n sum=0.d0\r\n do 12 k=1,n\r\n sum=sum+f(k)*cos((PI*(j-1))*((k-0.5d0)/n))\r\n12 continue\r\n c(j)=fac*sum\r\n13 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "c3199684a0a80fd6c1f1946486415b6363fb0538", "size": 588, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chebft.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/chebft.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/chebft.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.52, "max_line_length": 53, "alphanum_fraction": 0.4761904762, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360931, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.8053192132310509}} {"text": "MODULE mathvars\n!\n! mathematical constants to 20 significant figures\n!\n REAL, PARAMETER :: PI =3.1415926535897932385 ! pi\n REAL, PARAMETER :: TWOPI=6.2831853071795864769 ! 2pi\n REAL, PARAMETER :: FPI3 =2.3561944901923449288 ! 4*pi/3\n REAL, PARAMETER :: SQPI =1.7724538509055160273 ! sqrt(pi)\n REAL, PARAMETER :: TSPI =1.1283791670955125739 ! 2/sqrt(pi)\n REAL, PARAMETER :: GAMMA=0.57721566490153286061! Euler Gamma\n REAL, PARAMETER :: ZETA3=1.2020569031595942854 ! zeta(3)\n REAL, PARAMETER :: EXP2E=3.1722189581254505277 ! exp(2*GAMMA)\n REAL, PARAMETER :: LOG2 =0.69314718055994530942! ln(2)\n REAL, PARAMETER :: LOG4 =1.3862943611198906188 ! ln(4)\n REAL, PARAMETER :: LOG8 =2.0794415416798359283 ! ln(8)\n REAL, PARAMETER :: LOG16=2.7725887222397812377 ! ln(16)\n REAL, PARAMETER :: THIRD=1./3. ! 1/3=0.333333....\n\nEND MODULE mathvars\n", "meta": {"hexsha": "2e4a103339b256e037001f45f4534ee0866240eb", "size": 955, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mathvars.f90", "max_stars_repo_name": "losalamos/clog", "max_stars_repo_head_hexsha": "651331fc7898aff34b72d14046ee28c8fc1a50d3", "max_stars_repo_licenses": ["BSD-3-Clause", "Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-19T15:09:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-08T01:58:20.000Z", "max_issues_repo_path": "mathvars.f90", "max_issues_repo_name": "losalamos/clog", "max_issues_repo_head_hexsha": "651331fc7898aff34b72d14046ee28c8fc1a50d3", "max_issues_repo_licenses": ["BSD-3-Clause", "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": "mathvars.f90", "max_forks_repo_name": "losalamos/clog", "max_forks_repo_head_hexsha": "651331fc7898aff34b72d14046ee28c8fc1a50d3", "max_forks_repo_licenses": ["BSD-3-Clause", "Unlicense"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-06-21T20:28:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-19T08:21:51.000Z", "avg_line_length": 47.75, "max_line_length": 74, "alphanum_fraction": 0.6397905759, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561685659695, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.805258068878251}} {"text": " subroutine standev(nsize, indata, trend, std)\n!-------------------------------------------------------------------\n! This is a program to obtain standard deviation of the linearly\n! detrended data\n! \n! PARAMETERS:\n! nsize : indata size\n! indata : input data\n! trend : the linear trend of \"indata\"\n! std : standard deviation\n!--------------------------------------------------------------------\n\n implicit none\n\n integer, intent(in) :: nsize\n real, dimension(nsize) :: indata\n real, dimension(nsize), intent(out):: trend\n real, intent(out) :: std\n real sigmaX, sigmaY, sigmaX2, sigmaXY, real_nsize, Xbar, Ybar, real_i\n integer :: i\n real :: trend_const, trend_slope, temp\n\n sigmaX = 0.0\n sigmaY = 0.0\n do i = 1, nsize\n sigmaX = sigmaX + real(i)\n sigmaY = sigmaY + indata(i)\n enddo\n\n real_nsize=real(nsize)\n\n Xbar=sigmaX/real_nsize\n Ybar=sigmaY/real_nsize\n\n sigmaX2 = 0.0\n sigmaXY = 0.0\n do i = 1, nsize\n real_i=real(i)\n sigmaX2 = sigmaX2+(real_i-xbar)*(real_i-xbar)\n sigmaXY = sigmaXY+(real_i-xbar)*(indata(i)-ybar)\n enddo\n\n trend_slope=sigmaXY/sigmaX2\n trend_const=Ybar-trend_slope*Xbar\n\n do i=1, nsize\n trend(i)= trend_const + trend_slope*real(i)\n enddo\n\n std=0.0\n\n do i=1,nsize\n temp= indata(i)-trend(i)\n std=std+temp*temp\n enddo\n std=std/real(nsize)\n std=sqrt(std)\n\n end subroutine standev\n\n", "meta": {"hexsha": "4f80e719edac011ff2429926bdaa6e0816d1153e", "size": 1534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eemdf90/standev.f90", "max_stars_repo_name": "mathnathan/EEMD", "max_stars_repo_head_hexsha": "c38a710fc363739f32c37aa8ceeaecc2a77d24f2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2015-02-05T10:11:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T06:15:58.000Z", "max_issues_repo_path": "eemdf90/test/standev.f90", "max_issues_repo_name": "mathnathan/EEMD", "max_issues_repo_head_hexsha": "c38a710fc363739f32c37aa8ceeaecc2a77d24f2", "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": "eemdf90/test/standev.f90", "max_forks_repo_name": "mathnathan/EEMD", "max_forks_repo_head_hexsha": "c38a710fc363739f32c37aa8ceeaecc2a77d24f2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2015-10-07T09:05:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T15:01:36.000Z", "avg_line_length": 25.1475409836, "max_line_length": 75, "alphanum_fraction": 0.5332464146, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632275178339, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.8052214968222896}} {"text": "! Calculating Pi with using method: \n! integral 4.0/(1+x^2) dx = p\t \n! \t Serial Version\t \nprogram pi_serial\nimplicit none\ninteger*8 :: num_steps = 1000000000\ninteger i\nreal*8 :: PI_ref=3.1415926535897932,step,x,pi\nreal*8 :: summation=0.0\nreal :: start,finish\ncall cpu_time(start)\nstep = 1/(1.0 * num_steps)\n\n\tdo i =1,num_steps\n\tx=((i-1)+0.5) * step\nsummation=summation + (4.0/(1.0+(x*x)))\n\tend do\n\tpi = step * summation\ncall cpu_time(finish)\n\twrite(*,*) \"Estimated value of pi =\",pi\n\twrite(*,*) \"Error =\", abs(PI_ref - pi)\n\twrite(*,*) \"Compute time=\", (finish-start),\" seconds\"\n\tend\n\n\n", "meta": {"hexsha": "ffd866c8a302922293bccda9baccf090a6eb6805", "size": 601, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/ftn/src/pi-serial.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-serial.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-serial.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": 23.1153846154, "max_line_length": 54, "alphanum_fraction": 0.6422628952, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144273, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.8052214965907798}} {"text": "program main\n ! solve the Schrodinger equation of a harmonic oscillator with exact diagonalization\n\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n ! local vars\n integer :: i, j, Nx, LWORK, INFO\n real(dp) :: Xmax, dx\n real(dp), allocatable :: x(:), Vpot(:), Ham(:,:), W(:), WORK(:), y(:)\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 ! memory dynamical allocation\n allocate(x(-Nx:Nx))\n allocate(Vpot(-Nx:Nx))\n\n dx = Xmax / dble(Nx)\n do i = -Nx, Nx\n x(i) = dx * dble(i)\n Vpot(i) = .5d0 * x(i)**2\n end do\n\n allocate(Ham(2 * Nx - 1, 2 * Nx - 1))\n Ham = 0.d0\n do i = 1, 2 * Nx - 1\n Ham(i,i) = Vpot(i - Nx) + 1.d0 / dx**2\n if (i > 1) Ham(i,i - 1) = -.5d0 / dx**2\n if (i < 2 * Nx - 1) Ham(i,i + 1) = -.5d0 / dx**2\n end do\n\n allocate(W(2 * Nx - 1))\n LWORK = 10 * (Nx - 1)\n allocate(WORK(LWORK))\n call DSYEV('V', 'U', 2 * Nx - 1, Ham, 2 * Nx - 1, W, WORK, LWORK, INFO)\n\n if (INFO == 0) then\n open(unit = 1, file = 'eigenvalue2.txt', status = 'unknown')\n open(unit = 2, file = 'wavefunction2.txt', status = 'unknown')\n\n ! output results\n do i = 1, 2 * Nx + 1\n write(1, '(i4,f20.12)') i, W(i)\n write(2, '(f12.6)', advance = 'no') x(i - Nx -1)\n do j = 1, 2 * Nx + 1\n write(2, '(f12.6)', advance = 'no') Ham(i,j)\n end do\n write(2, *)\n end do\n close(1)\n close(2)\n else\n write(*, *) 'Diagonalization went wrong! aborting ...'\n stop\n end if\n\n deallocate(Ham)\n deallocate(W, WORK)\n deallocate(x, Vpot)\n\nend program main\n", "meta": {"hexsha": "269975a2c8072c4869c9eab7b3e1b14805aa54dd", "size": 1941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-2-Assignment-1/Exercises/1DHO-ExactDiagonalization.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/Exercises/1DHO-ExactDiagonalization.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/Exercises/1DHO-ExactDiagonalization.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": 26.5890410959, "max_line_length": 88, "alphanum_fraction": 0.4858320453, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.855851154320682, "lm_q1q2_score": 0.8051759928761355}} {"text": "SUBROUTINE simul2 ( 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 simul2\n\nPROGRAM gauss_jordan2\nIMPLICIT NONE\nINTEGER, PARAMETER :: MAX_SIZE = 10\nREAL, DIMENSION(MAX_SIZE, MAX_SIZE) :: a\nREAL, DIMENSION(MAX_SIZE) :: b\nREAL, DIMENSION(MAX_SIZE) :: soln\nINTEGER :: error\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\n ! If the number of equations is <= MAX_SIZE, read them in\n ! and process them.\n size_ok: IF (n <= MAX_SIZE) THEN\n READ(1, *) (a(i, j), j = 1, n), b(i)\n !END DO\n\n ! Display coefficients.\n WRITE(*, \"(/,'Coefficients before call:')\")\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 simul2(a, b, soln, MAX_SIZE, n, 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, 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 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\nEND PROGRAM gauss_jordan2\n", "meta": {"hexsha": "5692585654526ade03a3e6bcb431889f9ec9f7c5", "size": 4481, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap9/gauss_jordan2.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/gauss_jordan2.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/gauss_jordan2.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": 28.7243589744, "max_line_length": 69, "alphanum_fraction": 0.6645837983, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.8051590866220167}} {"text": "program happy\n\n implicit none\n integer, parameter :: find = 8\n integer :: found\n integer :: number\n\n found = 0\n number = 1\n do\n if (found == find) then\n exit\n end if\n if (is_happy (number)) then\n found = found + 1\n write (*, '(i0)') number\n end if\n number = number + 1\n end do\n\ncontains\n\n function sum_digits_squared (number) result (result)\n\n implicit none\n integer, intent (in) :: number\n integer :: result\n integer :: digit\n integer :: rest\n integer :: work\n\n result = 0\n work = number\n do\n if (work == 0) then\n exit\n end if\n rest = work / 10\n digit = work - 10 * rest\n result = result + digit * digit\n work = rest\n end do\n\n end function sum_digits_squared\n\n function is_happy (number) result (result)\n\n implicit none\n integer, intent (in) :: number\n logical :: result\n integer :: turtoise\n integer :: hare\n\n turtoise = number\n hare = number\n do\n turtoise = sum_digits_squared (turtoise)\n hare = sum_digits_squared (sum_digits_squared (hare))\n if (turtoise == hare) then\n exit\n end if\n end do\n result = turtoise == 1\n\n end function is_happy\n\nend program happy\n", "meta": {"hexsha": "5079f8810a350f6839786981dbd6e239c2409532", "size": 1229, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Happy-numbers/Fortran/happy-numbers.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/Happy-numbers/Fortran/happy-numbers.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/Happy-numbers/Fortran/happy-numbers.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.0735294118, "max_line_length": 59, "alphanum_fraction": 0.5915378356, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.8050908924836276}} {"text": "PROGRAM q2\n IMPLICIT NONE \n REAL:: a, b, AreaTR, AreaSR, Coeff\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, AreaTR, N)\n WRITE(*, *) \"Area using Trapezoidal Rule is: \", AreaTR\n Coeff = sqrt(1./AreaTR)\n WRITE(*, *) \"Coefficient A from Trapezoidal is: \", Coeff\n\n CALL SimpsonsRule(a, b, AreaSR, N)\n WRITE(*, *) \"Area using Simpsons Rule is: \", AreaSR\n Coeff = sqrt(1./AreaSR)\n WRITE(*, *) \"Coefficient A from Simpsons is: \", Coeff\n\n CONTAINS\n SUBROUTINE TrapezoidalRule(a, b, Area, N)\n IMPLICIT NONE \n REAL:: a, b, Area, Xi, h\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 h = (b-a)/N\n Area = (f(a) + f(b)) / 2.0\n DO i = 1, N-1\n Xi = a + i * h\n Area = Area + f(Xi)\n ENDDO\n Area = h * Area\n END SUBROUTINE TrapezoidalRule\n\n SUBROUTINE SimpsonsRule(a, b, Area, N)\n IMPLICIT NONE \n REAL:: a, b, Area, h\n INTEGER:: N, i\n ! N is number of segment\n IF(N .LT. 2) THEN\n Area = 0.0\n RETURN \n ENDIF\n h = (b-a)/N\n Area = f(a) + f(b)\n DO i = 1, N/2\n Area = Area + 4 * f(a + (2*i - 1) * h) \n ENDDO\n DO i = 1, (N+1)/2 - 1\n Area = Area + 2 * f(a + 2 * i * h)\n ENDDO\n Area = (h/3) * Area\n END SUBROUTINE SimpsonsRule\n\n REAL FUNCTION f(x)\n IMPLICIT NONE \n REAL:: x \n f = EXP(-x**2)**2\n return\n END FUNCTION f\n\nEND PROGRAM q2\n", "meta": {"hexsha": "102ac46ad7d486e1ada40e5500c88a6ef2f054b8", "size": 1784, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Numerical Integration/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": "Numerical Integration/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": "Numerical Integration/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": 26.6268656716, "max_line_length": 74, "alphanum_fraction": 0.4764573991, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291502, "lm_q2_score": 0.8633916099737807, "lm_q1q2_score": 0.805072358700386}} {"text": "module graphite_mod\n implicit none\n contains\n\n subroutine inverse_3_3 (A,Ainv)\n\n real(kind=8), dimension(3,3), intent(in) :: A\n real(kind=8), dimension(3,3), intent(out) :: Ainv\n real(kind=8) :: detA\n integer :: i, j\n\n if (size(A,1) .ne. 3) then\n write(*,*) \"matrix is not 3x3\"\n stop\n end if\n\n if (size(A,2) .ne. 3) then\n write(*,*) \"matrix is not 3x3\"\n stop\n end if\n\n ! Determine the determinant\n detA = A(1,1)*A(2,2)*A(3,3) - A(1,1)*A(2,3)*A(3,2) - &\n A(1,2)*A(2,1)*A(3,3) + A(1,2)*A(2,3)*A(3,1) + &\n A(1,3)*A(2,1)*A(3,2) - A(1,3)*A(2,2)*A(3,1)\n write(*,*) \"detA:\", detA\n\n if (dabs(detA) .le. 0.0000000001) then\n write(*,*) \"matrix is sinuglar (detA ~ 0)\"\n stop\n end if\n\n ! Determine the inverse:\n Ainv(1,1) = 1/detA * (A(2,2)*A(3,3) - A(3,2)*A(2,3))\n Ainv(1,2) = 1/detA * (A(1,3)*A(3,2) - A(3,3)*A(1,2))\n Ainv(1,3) = 1/detA * (A(1,2)*A(2,3) - A(2,2)*A(1,3))\n Ainv(2,1) = 1/detA * (A(2,3)*A(3,1) - A(3,3)*A(2,1))\n Ainv(2,2) = 1/detA * (A(1,1)*A(3,3) - A(3,1)*A(1,3))\n Ainv(2,3) = 1/detA * (A(1,3)*A(2,1) - A(2,3)*A(1,1))\n Ainv(3,1) = 1/detA * (A(2,1)*A(3,2) - A(3,1)*A(2,2))\n Ainv(3,2) = 1/detA * (A(1,2)*A(3,1) - A(3,2)*A(1,1))\n Ainv(3,3) = 1/detA * (A(1,1)*A(2,2) - A(2,1)*A(1,2))\n do i = 1, 3\n write(*,*) (Ainv(i,j), j = 1, 3)\n end do\n\n end subroutine inverse_3_3\n\nend module graphite_mod\n", "meta": {"hexsha": "8ddeaec2668e0fd3868a55b6352060d5e948591d", "size": 1499, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "1_generate_initial_structures/Generate_crystal_coordinates/graphite/with_dangling_bonds/module.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": "1_generate_initial_structures/Generate_crystal_coordinates/graphite/with_dangling_bonds/module.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": "1_generate_initial_structures/Generate_crystal_coordinates/graphite/with_dangling_bonds/module.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": 29.98, "max_line_length": 60, "alphanum_fraction": 0.4569713142, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8670357666736773, "lm_q1q2_score": 0.8049636361761816}} {"text": "program linear_system_test\n\n !Undergraduate Student: Arturo Burgos\n !Professor: João Rodrigo Andrade\n !Federal University of Uberlândia - UFU, Fluid Mechanics Laboratory\n !MFLab, Block 5P, Uberlândia, MG, Brazil\n\n !Fourth exercise: Solving a Linear System --> ax = b\n\n\n implicit none !To avoid variable definition problems, checking if they are correctly defined\n \n\n integer :: i, j, k, n, ite\n real, DIMENSION(:,:), ALLOCATABLE :: mtx_a\n real, DIMENSION(:), ALLOCATABLE :: mtx_b\n DOUBLE PRECISION :: start, finish\n DOUBLE PRECISION :: erro, tol\n DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: x_k, x_k1\n\n \n \n n = 9\n k = int(SQRT(real(n)))\n\n ALLOCATE (mtx_a(n,n))\n ALLOCATE (mtx_b(n))\n\n \n\n ! Set the A matrix\n\n do i = 1,n\n do j = 1,n\n if (i==j) then\n \n mtx_a(i,j) = -4\n \n else if (i==j-3 .or. i==j+3) then\n\n mtx_a(i,j) = 1\n\n else if ((mod(i,3)/=0 .and. j==i+1).or.(mod(i,3)/=1 .and. j==i-1)) then\n \n mtx_a(i,j) = 1\n\n else\n\n mtx_a(i,j) = 0\n \n end if\n end do\n end do\n\n\n ! Show Matrix A in the output\n\n print*, 'The matrix A is: '\n write(*,'(/A)')\n\n do i = 1,n\n\n write(*,1) int(mtx_a(i,:))\n 1 format(9i3)\n !write(*,1) mtx_a(i,:)\n !1 format(16f5.0)\n \n end do\n\n\n ! Set the B matrix\n\n do i = 1,k\n if (i tol)\n\n do i = 1,n\n\n x_k1(i) = mtx_b(i)\n\n do j = 1,n\n if (j/=i) then\n\n x_k1(i) = x_k1(i) - mtx_a(i,j)*x_k(j)\n\n endif\n end do\n\n x_k1(i) = x_k1(i)/mtx_a(i,i)\n\n end do\n\n erro = norma(x_k1,x_k)\n x_k = x_k1\n ite = ite + 1\n\n end do\n call cpu_time(finish)\n\n write(*,'(/A)')\n\n print *,'Elapsed time is:',finish - start\n print *, 'Solution: '\n write(*,6) real(x_k1)\n 6 format(9f7.2)\n print *, 'Iterations: ',ite\n\n \n\n contains\n \n function norma(vec1,vec2) result(y)\n\n implicit none\n\n \n DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: vec1, vec2\n DOUBLE PRECISION :: y\n\n \n y = maxval(ABS(vec1 - vec2))\n\n end function norma \n\nend program linear_system_test", "meta": {"hexsha": "7879797a57142ac72e52278b8bbdde5ccf18f8cf", "size": 3347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Linear System/Fortran/linear_system_test.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/linear_system_test.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/linear_system_test.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": 16.735, "max_line_length": 96, "alphanum_fraction": 0.4562294592, "num_tokens": 1065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8670357615200475, "lm_q1q2_score": 0.8049636348264212}} {"text": "program problem_34\n implicit none\n logical :: isCurious\n integer(kind = 8) :: i, total\n integer :: pow\n\n pow = 5\n total = 0\n do i = 10, 10 ** pow ! This limit was just a guess, there must be a reason but I don't know it.\n if (isCurious(i, pow)) then\n total = total + i\n endif\n enddo\n print *, total\n\nend program problem_34\n\nlogical function isCurious(number, pow)\n implicit none\n integer(kind = 8) :: number\n integer :: factorial, local_pow, pow, suma, remainder, digit\n\n local_pow = pow\n remainder = number\n suma = 0\n do while (local_pow .GT. -1)\n if (modulo(remainder, 10 ** local_pow) .NE. number) then\n digit = remainder / (10 ** local_pow)\n remainder = modulo(remainder, 10 ** local_pow)\n suma = suma + factorial(digit)\n if (suma .GT. number) then\n isCurious = .FALSE.\n return\n endif\n endif\n local_pow = local_pow - 1\n enddo\n\n isCurious = (suma .EQ. number)\n return\n\nend function isCurious\n\nrecursive function factorial(n) result(total)\n implicit none\n integer :: n, total\n if (n .EQ. 0) then\n total = 1\n else\n total = n * factorial(n - 1)\n endif\n\nend function factorial", "meta": {"hexsha": "d85c89fffbe16b9de6559d1199983c3c23ab9e30", "size": 1292, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_34/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_34/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_34/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.3773584906, "max_line_length": 99, "alphanum_fraction": 0.5750773994, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.8049636311463746}} {"text": "!##############################################################################\n! PROGRAM jacobi\n!\n! ## Use Jacobi iteration algorithm to solve linear equation system\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 jacobi\n\n implicit none\n integer :: iter, i\n real*8 :: A(3, 3), Dinv(3, 3), ID(3, 3), C(3, 3)\n real*8 :: b(3), d(3), x(3), xold(3)\n\n ! set up matrices and vectors\n A(1, :) = (/ 2d0, 0d0, 1d0/)\n A(2, :) = (/ 0d0, 4d0, 1d0/)\n A(3, :) = (/ 1d0, 1d0, 2d0/)\n b = (/30d0, 40d0, 30d0/)\n\n ID = 0d0\n Dinv = 0d0\n do i = 1, 3\n ID(i, i) = 1d0\n Dinv(i, i) = 1d0/A(i, i)\n enddo\n\n ! calculate iteration matrix and vector\n C = ID-matmul(Dinv, A)\n d = matmul(Dinv, b)\n\n ! initialize xold\n xold = 0d0\n\n ! start iteration\n do iter = 1, 200\n\n x = d + matmul(C, xold)\n\n write(*,'(i4,f12.7)')iter, maxval(abs(x-xold))\n\n ! check for convergence\n if(maxval(abs(x-xold)) < 1d-6)then\n write(*,'(/a,3f12.2)')' x = ',(x(i),i=1,3)\n stop\n endif\n\n xold = x\n enddo\n\n write(*,'(a)')'Error: no convergence'\n\nend program\n", "meta": {"hexsha": "22defa8c04149cb78283c4018943a7599878c5ea", "size": 1458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_04/prog02_04.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_04/prog02_04.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_04/prog02_04.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": 23.9016393443, "max_line_length": 79, "alphanum_fraction": 0.4602194787, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365572, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8048902768404048}} {"text": "PROGRAM ecoCheck\n\n! Adapted and updated to f90 by Rohit Goswami\n! and Shaivya Anand\n! from Kayode's Fortran programs for chemical\n! process design analysis and simulation\n! (c) 2018 Rohit Goswami [HaoZeke] \n! License: MIT\n! ******************************************************************\n! * THIS PROGRAM CALCULATES THE YEARLY CASH FLOWS, THE CUMULATIVE\n! * CASH FLOWS, DISCOUNT FACTORS AT A GIVEN RATE AND PRESENT\n! * VALUES. THE PROGRAM FURTHER CALCULATES THE NET PRESENT VALUE,\n! * PRESENT VALUE RATIO, THE AVERAGE RATE OF RETURN, THE NET\n! * RETURN RATE, AND THE PAYBACK PERIOD.\n! ******************************************************************\n! ARR = AVERAGE RATE OF RETURN\n! YCF = YEARLY CASH FLOW\n! DF = DISCOUNT FACTOR\n! CUCF = CUMULATIVE CASH FLOW\n! NPV = NET PRESENT VALUE\n! NOCF = NUMBER OF PROJECT LIFE EXCLUDING YEAR 0\n! NRR = NET RETURN RATE\n! PV = PRESENT VALUE\n! PVR = PRESENT VALUE RATIO\n! TIME = PAYBACK PERIOD\n! ******************************************************************\n\nREAL*8 YCF, DF, PV, NPV, CUCF\nEXTERNAL XNPV\nREAL NRR\n\nINTEGER TIME, TIME1\n\nDIMENSION YCF(0:100), DF(0:100), PV(0:100), CUCF(0:100)\n!\nOPEN (UNIT = 3, FILE = 'DATA91_B.DAT', STATUS ='OLD', ERR=18)\nOPEN (UNIT = 1, FILE = 'PRN_ECO_B')\n! READ THE NUMBER OF YEARLY CASH FLOWS EXCLUDING YEAR 0: NOCF\nREAD (3, *, ERR=19) NOCF\n! READ THE ANNUAL DISCOUNT RATE IN PERCENTAGE: DISC\n! READ THE YEARLY CASH FLOW: YCF\nREAD (3, *, ERR=19) DISC\nREAD (3, *, ERR=19) (YCF(K), K = 0, NOCF)\n\nGO TO 10\n\n18 WRITE (*, 21)\n21 FORMAT (6X,'DATA FILE DOES NOT EXIST')\n\nGO TO 999\n\n19 WRITE (*, 23)\n23 FORMAT(6X,'ERROR MESSAGE IN THE DATA VALUE')\n\nGO TO 999\n\n10 WRITE (1, 100)\n100 FORMAT (//,25X,'NET PRESENT VALUE CALCULATION',/1H, 78(1H*))\n\nNOCF1 = NOCF + 1\n\nWRITE (1, 110) NOCF1\n110 FORMAT(/,20X,I4,3X,'YEARLY CASH FLOWS INCLUDING YEAR 0')\n\nWRITE (1, 120) DISC\n120 FORMAT (/,20X,F8.2,3X,'PERCENTAGE ANNUAL DISCOUNT RATE ',/, &\n& 1H, 78(1H-))\n\nWRITE (1, 130)\n130 FORMAT (//, 7X,'YEAR', 5X, 'CASH FLOWS ($)', 4X, 'CUMULATIVE', &\n& 10X, 'DISCOUNT', 8X, 'PRESENT')\n\nWRITE (1, 140)\n140 FORMAT (34X,'CASH FLOWS ($)', 6X, 'FACTOR', 10X, 'VALUE ($)', &\n& /,1H, 78(1H-))\n\n! CALCULATE THE CUMULATIVE CASH FLOW\n\n\nCUCF(0) = YCF(0)\nDO I = 1, NOCF\nCUCF(I) = CUCF(I-1) + YCF(I)\nEND DO\n\nR1 = DISC/100.0\nPV(0) = YCF(0)*1.0\n\nDO 15 I1 = 0, 0\nIF (I1 .EQ. 0) THEN\nR1 = 0.0\nDF(I1) = 1.0/((1.0+R1)**I1)\nPV(I1) = YCF(I1)*DF(I1)\nELSE\nENDIF\n15 END DO\n\nR1 = DISC/100.0\n\nDO 20 I1 = 1, NOCF\nDF(I1) = 1.0/((1.0+R1)**I1)\nPV(I1) = YCF(I1)*DF(I1)\n20 END DO\n\nDO K = 0, NOCF\nWRITE (1, 150) K, YCF(K), CUCF(K), DF(K), PV(K)\n150 FORMAT (5X,I3,5X,F14.2,5X,F14.2,5X,F9.4,5X,F14.2)\nEND DO\n\nWRITE (1, 160)\n160 FORMAT (78(1H-))\n\n! CALCULATE THE NET PRESENT VALUE FROM THE PRESENT VALUE\n\nNPV = 0.0\nDO J = 0, NOCF\nNPV = NPV + PV(J)\nEND DO\n\nWRITE (1, 170) NPV\n170 FORMAT (1H0, 6X,'THE NET PRESENT VALUE ($):', 3X, T40, F14.2)\n\n! CALCULATE THE PRESENT VALUE RATIO, PVR\n! PVR = PRESENT VALUE OF ALL POSITIVE CASH FLOWS/\n! PRESENT VALUE OF ALL NEGATIVE CASH FLOWS\nSUM1 = 0.0\n\nDO K = 1, NOCF\nSUM1 = SUM1 + PV(K)\nEND DO\n\nPVR = SUM1 /ABS(YCF(0))\n\nWRITE (1, 180) PVR\n180 FORMAT (1H0, 6X, 'PRESENT VALUE RATIO:', 3X, T40, F8.3)\n\n! CALCULATE THE NET RETURN RATE (NRR) i.e. THE NET PRESENT VALUE\n! DIVIDED BY THE PRODUCT OF INITIAL INVESTMENT AND THE PROJECT LIFE\n! (EXCLUDING YEAR 0).\n\nNRR = ABS(NPV/(ABS(PV(0))*NOCF))*100\n\nWRITE(1, 190) NRR\n190 FORMAT (1H0, 6X, 'THE NET RETURN RATE:', 3X, T40, F8.2, 3X, '%')\n\n! CALCULATE THE AVERAGE RATE OF RETURN (ARR) i.e THE AVERAGE\n! CASH FLOW DURING THE LIFE OF THE PROJECT (EXCLUDING YEAR 0).\n\nSUM = 0.0\nDO I = 1, NOCF\nSUM = SUM + YCF(I)\nEND DO\n\nAVSUM = SUM/NOCF\nARR = (AVSUM/ABS(YCF(0)))*100.0\n\nWRITE (1, 200) ARR\n200 FORMAT(1H0, 6X, 'THE AVERAGE RATE OF RETURN:', 3X, T40, F8.2, &\n& 3X,'%')\n\n! CALCULATE THE PAYBACK TIME FROM THE CUMULATIVE CASH FLOW, TIME: YE\n\nDO I=0, NOCF\nIF ( CUCF(I+1) .GT. CUCF(I) .AND. CUCF(I+1) .GE. 0.0) THEN\nTEMP = CUCF(I+1)\nCUCF(I+1) = CUCF(I)\nCUCF(I) = TEMP\nTIME = I\nTIME1 = TIME + 1\nGO TO 40\nELSE\nENDIF\nEND DO\n\n40 WRITE (1, 210) TIME, TIME1\n210 FORMAT (1H0,6X,'THE PAYBACK PERIOD IS BETWEEN:', &\n& 3X,T45,I2,2X,'AND',2X,I2,3X,'YEARS')\n\n! FORM FEED THE PRINTING PAPER TO TOP OF THE NEXT PAGE.\n\nWRITE(1, *) CHAR(12)\n\nCLOSE (3, STATUS = 'KEEP')\nCLOSE (1)\n\n999 STOP\nEND\n", "meta": {"hexsha": "d3986f52a36bd54178962cdf3002ffc4a063fb0a", "size": 4547, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/prog91_eco.f90", "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.f90", "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.f90", "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": 24.3155080214, "max_line_length": 72, "alphanum_fraction": 0.5898394546, "num_tokens": 1805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.8048902765308148}} {"text": "program C20211219 !Solving definite integral by rectangular method\r\nimplicit none\r\n integer n , i\r\n real S,dx,a,b\r\n real h\r\n real, external :: rectangle,f,f1,f2,f3,f4,f5,f6\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 h = f(a+(i-0.5)*dx)\r\n S = S + rectangle(h,dx)\n end do\r\n write(*,\"('y=',F8.1)\") S\r\n\nend program\r\n\r\nreal function rectangle(h,dx)\r\nimplicit none\r\n real,intent(in):: h,dx\r\n rectangle = h * dx\r\n return\nend function\r\n\r\nreal function f(x)\r\nimplicit none\r\n real,intent(in):: x\r\n real, external :: f1,f2,f3,f4,f5,f6\r\n if(x<0) then\r\n f = f1(x)\r\n else if(x>=0 .and. x<1) then\r\n f = f2(x)\r\n else if(x>=1 .and. x<4) then\r\n f = f3(x)\r\n else if(x>=4 .and. x<16) then\r\n f = f4(x)\r\n else if(x>=16 .and. x<64) then\r\n f = f5(x)\r\n else if(x>=64) then\r\n f = f6(x)\n end if\r\n\r\n return\nend function\r\n\r\nreal function f1(x)!x<0\r\nimplicit none\r\n real,intent(in):: x\r\n f1 = 1 - exp(x)\r\n return\nend function\r\n\r\nreal function f2(x)!x>=0 .and. x<1\r\nimplicit none\r\n real,intent(in):: x\r\n f2 = x**4\r\n return\nend function\r\n\r\nreal function f3(x)!x>=1 .and. x<4\r\nimplicit none\r\n real,intent(in):: x\r\n f3 = x**3\r\n return\nend function\r\n\r\nreal function f4(x)!x>=4 .and. x<16\r\nimplicit none\r\n real,intent(in):: x\r\n f4 = x**2 + 48\r\n return\nend function\r\n\r\nreal function f5(x)!x>=16 .and. x<64\r\nimplicit none\r\n real,intent(in):: x\r\n f5 = x + 288\r\n return\nend function\r\n\r\nreal function f6(x)!x>=64\r\nimplicit none\r\n real,intent(in):: x\r\n f6 = x**0.5 + 344\r\n return\nend function\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "5723183dbaa99ccd72304ae81c2b617351640e15", "size": 1664, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/C20211219.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/C20211219.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/C20211219.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": 18.0869565217, "max_line_length": 67, "alphanum_fraction": 0.5330528846, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.8048185064770975}} {"text": " FUNCTION BESSJ (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\t IMPLICIT NONE\n REAL *8 X,BESSJ,BESSJ0,BESSJ1,TOX,BJM,BJ,BJP,SUM,BIGNO,BIGNI\n INTEGER N,JSUM,M,J,IACC\n PARAMETER (IACC = 101,BIGNO = 1.D10, BIGNI = 1.D-10)!IACC=40\n\n IF (N.EQ.0) THEN\n BESSJ = BESSJ0(X)\n RETURN\n ENDIF\n IF (N.EQ.1) THEN\n BESSJ = BESSJ1(X)\n RETURN\n ENDIF\n IF (X.EQ.0.) THEN\n BESSJ = 0.\n RETURN\n ENDIF\n TOX = 2./X\n IF (X.GT.FLOAT(N)) THEN\n BJM = BESSJ0(X)\n BJ = BESSJ1(X)\n DO 11 J = 1,N-1\n BJP = J*TOX*BJ-BJM\n BJM = BJ\n BJ = BJP\n 11 CONTINUE\n BESSJ = BJ\n ELSE\n M = 2*((N+INT(SQRT(FLOAT(IACC*N))))/2)\n BESSJ = 0.\n JSUM = 0\n SUM = 0.\n BJP = 0.\n BJ = 1.\n DO 12 J = M,1,-1\n BJM = J*TOX*BJ-BJP\n BJP = BJ\n BJ = BJM\n IF (ABS(BJ).GT.BIGNO) THEN\n BJ = BJ*BIGNI\n BJP = BJP*BIGNI\n BESSJ = BESSJ*BIGNI\n SUM = SUM*BIGNI\n ENDIF\n IF (JSUM.NE.0) SUM = SUM+BJ\n JSUM = 1-JSUM\n IF (J.EQ.N) BESSJ = BJP\n 12 CONTINUE\n SUM = 2.*SUM-BJ\n BESSJ = BESSJ/SUM\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "c56131c8a3642c50c7406bd173202cdf607f9e1b", "size": 1517, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/bessj.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/bessj.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/bessj.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": 23.703125, "max_line_length": 72, "alphanum_fraction": 0.5273566249, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.8047974775163623}} {"text": "!------------------------------------------------\r\n module MathConstantsMod\r\n use PrecisionMod\r\n implicit none\r\n! Frequently used mathematical constants (with precision to spare):\r\n real(dp), parameter :: zero = 0.0_dp\r\n real(dp), parameter :: one = 1.0_dp\r\n real(dp), parameter :: two = 2.0_dp\r\n complex(dpc), parameter :: xi = (0.0_dp,1.0_dp)\r\n real(sp), parameter :: sqrt2 = 1.41421356237309504880168872420969807856967_sp\r\n\r\n real(sp), parameter :: pi = 3.141592653589793238462643383279502884197_sp\r\n real(sp), parameter :: pio2 = 1.57079632679489661923132169163975144209858_sp\r\n real(sp), parameter :: twopi = 6.283185307179586476925286766559005768394_sp \r\n real(dp), parameter :: pi_d = 3.141592653589793238462643383279502884197_dp\r\n real(dp), parameter :: pio2_d = 1.57079632679489661923132169163975144209858_dp\r\n real(dp), parameter :: twopi_d = 6.283185307179586476925286766559005768394_dp\r\n \r\n end module MathConstantsMod \r\n!------------------------------------------------\r\n!\r\n module PhysConstantsMod\r\n use PrecisionMod\r\n implicit none\r\n real(dp), parameter :: BohrR = 5.29177249e-11\r\n real(dp), parameter :: e2Overhbar = 0.000243413479154821 !(1/Ohm)\r\n end module PhysConstantsMod\r\n", "meta": {"hexsha": "1a08e5074a8ea0871333df183a8b7b1737d901d5", "size": 1254, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ConstantsMod.f90", "max_stars_repo_name": "RezaNourafkan/Transport-", "max_stars_repo_head_hexsha": "e9eedcbec3672a824f1b2e3d59bd38e68cd7437c", "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/ConstantsMod.f90", "max_issues_repo_name": "RezaNourafkan/Transport-", "max_issues_repo_head_hexsha": "e9eedcbec3672a824f1b2e3d59bd38e68cd7437c", "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/ConstantsMod.f90", "max_forks_repo_name": "RezaNourafkan/Transport-", "max_forks_repo_head_hexsha": "e9eedcbec3672a824f1b2e3d59bd38e68cd7437c", "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": 44.7857142857, "max_line_length": 84, "alphanum_fraction": 0.6610845295, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8046512365098648}} {"text": "program matrix_multiplication\n implicit none\n integer :: m, n, p\n integer, allocatable :: a(:, :), b(:, :), c(:, :)\n integer :: i, j, k, summa\n character(len=128) :: tmpstr\n\n ! Get extents of the matrices.\n read *, m, n, p\n\n allocate(a(m, n), b(n, p), c(m, p))\n\n do i = 1, m\n read *, a(i, :)\n end do\n do i = 1, n\n read *, b(i, :)\n end do\n\n ! 1st way: multiplication in explicit loops.\n first_1: do i = 1, m\n last_1: do j = 1, p\n summa = 0\n middle_1: do k = 1, n\n summa = summa + a(i, k) * b(k, j)\n end do middle_1\n c(i, j) = summa\n end do last_1\n end do first_1\n\n ! 2nd way: multiplication in two outer loops with a slice in between.\n first_2: do i = 1, m\n last_2: do j = 1, p\n c(i, j) = sum(a(i, :) * b(:, j))\n end do last_2\n end do first_2\n\n ! 3rd way: multiplication sing intrinsic function matmul(). It applies only\n ! for matrices up to rank 2.\n c = matmul(a, b)\n\n ! Print the resulting matrix.\n do i = 1, m\n print *, c(i, :)\n end do\n\n deallocate(a, b, c)\nend program matrix_multiplication\n", "meta": {"hexsha": "9b3b0213d3cd4567c6edabb9d60bc561ad44fe61", "size": 1190, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_02/matrix_multiplication/matrix_multiplication.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_02/matrix_multiplication/matrix_multiplication.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_02/matrix_multiplication/matrix_multiplication.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.2857142857, "max_line_length": 80, "alphanum_fraction": 0.5092436975, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966641739773, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.8045798777227723}} {"text": "FUNCTION heatunit(tmax,tmin,thres)\n!\nIMPLICIT NONE\n!\n! PARAMETER definitions\n!\nREAL,PARAMETER :: pi = 3.1415927\n!\n! Function arguments\n!\nREAL :: thres,tmax,tmin\nREAL :: heatunit\n!\n! Local variables\n!\nREAL :: range,theta,tmean\n!\n! calculates the amount of heat units in degree-days above a\n! threshold temperature assuming a fully sinusoidal daily\n! temperature cycle with maximum and minimum 12 hours apart.\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! tmax - maximum daily air temperature\n! tmin - minimum daily air temperature\n! thres - threshold temperature (such as minimum temperature for growth)\n \n! + + + local variables + +\n \n! + + + local variable definitions + + +\n! tmean - arithmetic average of tmax and tmin\n! range - daily range of maximum and minimum temperature\n! theta - point where threshold and air temperature are equal\n! defines integration limits\n \n! + + + parameters + + +\n \n! + + + end initializations + + +\n \nIF (thres.GE.tmax) THEN\n heatunit = 0.0\nELSE IF ((thres.LE.tmin).OR.(tmax.LE.tmin)) THEN\n tmean = (tmax+tmin)/2.0\n heatunit = tmean - thres\nELSE\n tmean = (tmax+tmin)/2.0\n range = (tmax-tmin)/2.0\n theta = asin((thres-tmean)/range)\n heatunit = ((tmean-thres)*(pi/2.0-theta)+range*cos(theta))/pi\nEND IF\n! \nEND FUNCTION heatunit\n", "meta": {"hexsha": "a7c43e334898a96eef5e50348cb33fa62dd0b2c8", "size": 1379, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Heatunit.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/Heatunit.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/Heatunit.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.537037037, "max_line_length": 77, "alphanum_fraction": 0.6540971719, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.8044641440348976}} {"text": "subroutine PlSchmidt_d1(p, dp, lmax, z)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function evalutates all of the Schmidt normalized legendre \n!\tpolynomials and their first derivatives 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\t\tdp:\tA vector of all associated 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!\t3.\tDerivatives are calculated according to the unnormalized relationships:\n!\t\t\tP'_0(z) = 0.0, P'_1(z) = 1.0, and\n!\t\t\tP'_l(z) = l * (P'_{l-1}(z) - z * P_l(z) ) / (1.0d0 - z**2)\n!\t\t\tAt z = 1, Pl(1) = 1, and P'l(1) = l (l+1) / 2 \t(Boyd 2001)\n!\t\t\tAt z = -1 Pl(-1) = (-1)**l, and P'l(-1) = (-1)**(l-1) l (l+1) / 2\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(:), dp(:)\n \treal*8, intent(in) ::\tz\n \treal*8 ::\tpm2, pm1, pl, sinsq\n \tinteger ::\tl\n\n\tif (size(p) < lmax+1) then\n\t\tprint*, \"Error --- PlSchmidt_d1\"\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 (size(dp) < lmax+1) then\n\t\tprint*, \"Error --- PlSchmidt_d1\"\n \t\tprint*, \"DP must be dimensioned as (LMAX+1) where LMAX is \", lmax \n \t\tprint*, \"Input array is dimensioned \", size(dp)\n \t\tstop\n \telseif (lmax < 0) then \n \t\tprint*, \"Error --- PlSchmidt_d1\"\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_d1\"\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\tif (z == 1.0d0) then\n \t\n \t\tp(1:lmax+1) = 1.0d0\n \t\tdo l=0, lmax\n \t\t\tdp(l+1) = dble(l)*dble(l+1)/2.0d0\n \t\tenddo\n \t\t\n \telseif (z == -1.0d0) then\n \t\t\n \t\tdo l=0, lmax\n \t\t\tp(l+1) = dble((-1)**l)\n \t\t\tdp(l+1) = dble(l)*dble(l+1) * dble((-1)**(l-1)) / 2.0d0\n \t\tenddo\n \t\n \telse\t\n\n\t\tsinsq = (1.0d0-z)*(1.0d0+z)\n\n \t\tpm2 = 1.0d0\n \t\tp(1) = 1.0d0\n \t\tdp(1) = 0.0d0\n \t\n \t\tpm1 = z\n \t\tp(2) = pm1\n \t\tdp(2) = 1.0d0\n \t\n \t\tdo l = 2, lmax\n \t\tpl = ( dble(2*l-1) * z * pm1 - dble(l-1) * pm2 ) / dble(l)\n \t\tp(l+1) = pl\n \t\tdp(l+1) = dble(l) * (pm1 - z * pl) / sinsq\n \t\tpm2 = pm1\n \t\tpm1 = pl\n \t\tenddo\n \t\t\n \tendif\n\nend subroutine PlSchmidt_d1\n\n", "meta": {"hexsha": "ee5c5f5ad67d73ff440f1a889c902bf45462e6f6", "size": 3073, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/PlSchmidt_d1.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_d1.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_d1.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.1274509804, "max_line_length": 83, "alphanum_fraction": 0.5011389522, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8558511451289038, "lm_q1q2_score": 0.8044259124490105}} {"text": " program demo_sin\n implicit none\n real :: d\n d = haversine(36.12,-86.67, 33.94,-118.40) ! BNA to LAX\n print '(A,F9.4,A)', 'distance: ',d,' km'\n contains\n function haversine(latA,lonA,latB,lonB) result (dist)\n !\n ! calculate great circle distance in kilometers\n ! given latitude and longitude in degrees\n !\n real,intent(in) :: latA,lonA,latB,lonB\n real :: a,c,dist,delta_lat,delta_lon,lat1,lat2\n real,parameter :: radius = 6371 ! mean earth radius in kilometers,\n ! recommended by the International Union of Geodesy and Geophysics\n\n ! generate constant pi/180\n real, parameter :: deg_to_rad = atan(1.0)/45.0\n delta_lat = deg_to_rad*(latB-latA)\n delta_lon = deg_to_rad*(lonB-lonA)\n lat1 = deg_to_rad*(latA)\n lat2 = deg_to_rad*(latB)\n a = (sin(delta_lat/2))**2 + &\n & cos(lat1)*cos(lat2)*(sin(delta_lon/2))**2\n c = 2*asin(sqrt(a))\n dist = radius*c\n end function haversine\n end program demo_sin\n", "meta": {"hexsha": "ee302f15d78d274f75d1cc6096507292345592ef", "size": 1011, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/sin.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/sin.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/sin.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": 34.8620689655, "max_line_length": 70, "alphanum_fraction": 0.6221562809, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611631680358, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.8044176842259352}} {"text": "PROGRAM stats_3\r\n!\r\n! Purpose:\r\n! To calculate mean and the standard deviation of an input\r\n! data set, where each input value can be positive, negative,\r\n! or zero.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/13/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nINTEGER :: i ! Loop index\r\nINTEGER :: n = 0 ! The number of input samples.\r\nREAL :: std_dev ! The standard deviation of the input samples.\r\nREAL :: sum_x = 0. ! The sum of the input values. \r\nREAL :: sum_x2 = 0. ! The sum of the squares of the input values. \r\nREAL :: x = 0. ! An input data value.\r\nREAL :: x_bar ! The average of the input samples.\r\n\r\n! Get the number of points to input.\r\nWRITE (*,*) 'Enter number of points: '\r\nREAD (*,*) n\r\n\r\n! Check to see if we have enough input data.\r\nIF ( n < 2 ) THEN ! Insufficient data\r\n\r\n WRITE (*,*) 'At least 2 values must be entered.'\r\n\r\nELSE ! we will have enough data, so let's get it.\r\n \r\n ! Loop to read input values.\r\n DO i = 1, n\r\n\r\n ! Read values\r\n WRITE (*,*) 'Enter number: '\r\n READ (*,*) x \r\n WRITE (*,*) 'The number is ', x \r\n\r\n ! Accumulate sums.\r\n sum_x = sum_x + x\r\n sum_x2 = sum_x2 + x**2\r\n\r\n END DO\r\n\r\n ! Now calculate statistics.\r\n x_bar = sum_x / real(n)\r\n std_dev = SQRT((real(n)*sum_x2 - sum_x**2) / (real(n)*real(n-1)))\r\n\r\n ! Tell user.\r\n WRITE (*,*) 'The mean of this data set is:', x_bar\r\n WRITE (*,*) 'The standard deviation is: ', std_dev\r\n WRITE (*,*) 'The number of data points is:', n\r\n\r\nEND IF\r\n\r\nEND PROGRAM stats_3\r\n", "meta": {"hexsha": "88df34927ed30cf2ad80ec91404293b5e0e33566", "size": 1757, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap4/stats_3.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/chap4/stats_3.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/chap4/stats_3.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.8032786885, "max_line_length": 69, "alphanum_fraction": 0.5640295959, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102533547801, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.8040563065026785}} {"text": "!******************************************************************************\n!*\n!* OPERATIONS ON MATRICES\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 11/2012\n ! \n ! 3) DESCRIPTION: implements various operations on matrices.\n !==========================================================================\n\nMODULE matrices\n\n USE utilities, ONLY:\n USE linear_system, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: determinant_matrix, invert_matrix\n PUBLIC :: invert_cholesky, determinant_cholesky\n\n\nCONTAINS\n\n\n !==========================================================================\n ! detA = DETERMINANT_LU(A[N,N][,NODECOMPOSITION])\n !\n ! Compute the determinant DETA of a square matrix A, using the LU \n ! decomposition method. The keyword NODECOMPOSITION has to be used\n ! if the input matrix has already been decomposed.\n !==========================================================================\n\n FUNCTION determinant_LU (A,d,nodecomposition)\n\n USE utilities, ONLY: DP\n USE linear_system, ONLY: LU_decomp\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:,:) :: A\n INTEGER, INTENT(IN), OPTIONAL :: d\n LOGICAL, INTENT(IN), OPTIONAL :: nodecomposition\n REAL(DP) :: determinant_LU\n\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: LU\n REAL(DP), DIMENSION(SIZE(A,1)) :: diag\n LOGICAL :: decomp\n INTEGER, DIMENSION(SIZE(A,1)) :: indx\n INTEGER :: N, i, dd\n\n !-----------------------------------------------------------------------\n\n N = SIZE(A,1)\n decomp = .True.\n IF (PRESENT(nodecomposition)) decomp = MERGE(.False.,.True.,nodecomposition)\n IF (decomp) THEN \n LU(:,:) = LU_DECOMP(A,indx,dd)\n ELSE \n LU(:,:) = A \n dd = d\n END IF\n FORALL (i=1:N) diag(i) = LU(i,i)\n determinant_LU = REAL(dd,DP) * PRODUCT(diag)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION determinant_LU\n\n\n !==========================================================================\n ! detA = DETERMINANT_CHOLESKY(A[N,N][,NODECOMPOSITION,NOPOSDEF])\n !\n ! Compute the determinant DETA of a positive definite matrix A, using the \n ! Cholesky decomposition method. The keyword NODECOMPOSITION has to be used\n ! if the input matrix has already been decomposed.\n !==========================================================================\n\n FUNCTION determinant_cholesky (A,nodecomposition,noposdef)\n\n USE utilities, ONLY: DP, NaN\n USE linear_system, ONLY: cholesky_decomp\n IMPLICIT NONE\n \n REAL(DP), DIMENSION(:,:), INTENT(IN) :: A\n LOGICAL, INTENT(IN), OPTIONAL :: nodecomposition\n LOGICAL, INTENT(OUT), OPTIONAL :: noposdef\n REAL(DP) :: determinant_cholesky\n\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: Chdcp\n REAL(DP), DIMENSION(SIZE(A,1)) :: diag\n LOGICAL :: decomp\n INTEGER :: i, N\n\n !-----------------------------------------------------------------------\n\n ! Cholesky decomposition\n N = SIZE(A,1)\n decomp = .True.\n IF (PRESENT(noposdef)) noposdef = .False.\n IF (PRESENT(nodecomposition)) decomp = MERGE(.False.,.True.,nodecomposition)\n IF (decomp) THEN \n IF (PRESENT(noposdef)) THEN \n Chdcp = CHOLESKY_DECOMP(A,noposdef) \n IF (noposdef) THEN\n determinant_cholesky = NaN()\n RETURN\n END IF\n ELSE\n Chdcp = CHOLESKY_DECOMP(A) \n END IF\n ELSE \n Chdcp = A\n END IF\n\n ! Compute the determinant\n FORALL (i=1:N) diag(i) = Chdcp(i,i)\n determinant_cholesky = EXP(2._DP*SUM(LOG(diag)))\n \n !-----------------------------------------------------------------------\n\n END FUNCTION determinant_cholesky\n\n\n !==========================================================================\n ! detA = DETERMINANT_MATRIX(A[N,N][,LU,Cholesky])\n !\n ! Overload of the computation of a determinant matrix A[N,N].\n !==========================================================================\n\n FUNCTION determinant_matrix (A,lu,Cholesky)\n \n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:,:) :: A\n LOGICAL, INTENT(IN), OPTIONAL :: lu, Cholesky\n REAL(DP) :: determinant_matrix\n\n CHARACTER(8) :: method\n\n !-----------------------------------------------------------------------\n\n method = \"LU \"\n IF (PRESENT(LU)) method = MERGE(\"LU \",\"Cholesky\",LU)\n IF (PRESENT(Cholesky)) method = MERGE(\"Cholesky\",method,Cholesky)\n\n SELECT CASE (method)\n CASE (\"LU \")\n determinant_matrix = DETERMINANT_LU(A)\n CASE (\"Cholesky\")\n determinant_matrix = DETERMINANT_CHOLESKY(A)\n CASE DEFAULT\n determinant_matrix = 0._DP\n END SELECT\n\n !-----------------------------------------------------------------------\n\n END FUNCTION determinant_matrix\n\n\n !==========================================================================\n ! invA[N,N] = INVERT_GAUSS(A[N,N])\n !\n ! Compute the inverse INVA of a square matrix A, with Gauss-Jordan \n ! elimination and full pivot.\n !==========================================================================\n\n FUNCTION invert_gauss (A)\n\n USE utilities, ONLY: DP\n USE linear_system, ONLY: linsyst_gauss\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:,:) :: A\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: invert_gauss\n\n REAL(DP), DIMENSION(SIZE(A,1),1) :: B\n\n !-----------------------------------------------------------------------\n \n B(:,:) = 0._DP\n B = LINSYST_GAUSS(A,B,invert_gauss,ONLY_INVERSE=.True.)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION invert_gauss\n\n\n !==========================================================================\n ! invA[N,N] = INVERT_LU(A[N,N][,determinant])\n !\n ! Compute the inverse INVA of a square matrix A, with Gauss-Jordan \n ! elimination and full pivot.\n !==========================================================================\n\n FUNCTION invert_LU (A,determinant)\n\n USE utilities, ONLY: DP\n USE linear_system, ONLY: LU_decomp, linsyst_LU\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:,:) :: A\n REAL(DP), INTENT(OUT), OPTIONAL :: determinant\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: invert_LU\n\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: B, LU\n INTEGER, DIMENSION(SIZE(A,1)) :: indx\n INTEGER :: i, N, d\n\n !-----------------------------------------------------------------------\n \n ! Solve for the identity matrix\n N = SIZE(A,1)\n B(:,:) = 0._DP\n FORALL (i=1:N) B(i,i) = 1._DP\n LU(:,:) = LU_DECOMP(A,indx,d)\n\n ! Loop on the number of systems\n DO i=1,N\n invert_LU(:,i) = LINSYST_LU(LU,B(:,i),indx)\n END DO\n\n ! Determinant\n IF (PRESENT(determinant)) &\n determinant = DETERMINANT_LU(LU,NODECOMPOSITION=.True.)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION invert_LU\n\n\n !==========================================================================\n ! invA[N,N] = INVERT_CHOLESKY(A[N,N][,determinant,noposdef])\n !\n ! Compute the inverse INVA of a positive definite matrix A, with Cholesky\n ! decomposition.\n !==========================================================================\n\n FUNCTION invert_cholesky (A,determinant,noposdef)\n\n USE utilities, ONLY: DP\n USE linear_system, ONLY: cholesky_decomp\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: A\n REAL(DP), INTENT(OUT), OPTIONAL :: determinant\n LOGICAL, INTENT(OUT), OPTIONAL :: noposdef\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: invert_cholesky\n\n REAL(DP), DIMENSION(SIZE(A,1),SIZE(A,2)) :: Chdcp\n INTEGER :: i, j, N\n\n !-----------------------------------------------------------------------\n\n ! Perform the Cholesky decomposition\n N = SIZE(A,1)\n IF (PRESENT(noposdef)) THEN\n Chdcp = CHOLESKY_DECOMP(A,noposdef)\n IF (noposdef) RETURN\n ELSE\n Chdcp = CHOLESKY_DECOMP(A)\n END IF \n \n ! Compute the inverse matrix\n row_low: DO i=1,N \n FORALL (j=1:i) &\n invert_cholesky(j,i) = (MERGE(1._DP,0._DP,i==j) &\n - DOT_PRODUCT(Chdcp(i,j:i-1),invert_cholesky(j,j:i-1))) &\n / Chdcp(i,i)\n END DO row_low\n row_up: DO i=N,1,-1\n FORALL (j=1:i)\n invert_cholesky(j,i) = (MERGE(0._DP,invert_cholesky(j,i),i= 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 end procedure\n !====================================================================!\n\n !====================================================================!\n module procedure std_i1D\n !! Interfaced with std()\n !====================================================================!\n !integer(i32) :: this(:)\n !real(r64) :: res\n res=dsqrt(Variance(this))\n end procedure\n !====================================================================!\n\n !====================================================================!\n module procedure Variance_i1D\n !====================================================================!\n !integer(i32) :: 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 !====================================================================!\nend submodule\n", "meta": {"hexsha": "84e2bbd9a812629e57bc5a7fd007842c68cc7133", "size": 5670, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths/sm_maths_i1D.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_i1D.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_i1D.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": 32.5862068966, "max_line_length": 72, "alphanum_fraction": 0.3957671958, "num_tokens": 1316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.8033498495003032}} {"text": "!------------------------------------------------------------------------------\n!\n! Program name:\n!\n! fibonacci\n!\n! Purpose:\n!\n! This program calls a recursive function to calculate the nth value of\n! the Fibonacci sequence. \n! fib(1) = 1, fib(2) = 1, fib(i) = fib(i-1) + fib(i-2), i.e.,\n! 1, 1, 2, 3, 5, 8, 13, ...\n!\n!\n!------------------------------------------------------------------------------\n\nPROGRAM fibonacci\n\n IMPLICIT NONE\n INTEGER :: n, nfib\n INTEGER, SAVE :: count = 0\n\n WRITE (*, *) 'Input n:' \n READ (*, *) n\n\n nfib = fib(n)\n WRITE (*, *) 'The nth value of the Fibonacci sequence, where n = ', n, &\n ', is: ', nfib\n WRITE (*, *) 'Function fib was invoked ', count, ' times.'\n\n CONTAINS\n \n RECURSIVE FUNCTION fib(n) RESULT(fib_result)\n\n INTEGER, INTENT(in) :: n\n INTEGER :: fib_result\n\n count = count + 1 ! Increment count of function calls\n\n SELECT CASE (n)\n CASE (1) ! First value is 1\n fib_result = 1\n CASE (2) ! Second value is 1\n fib_result = 1\n CASE (3:)\n fib_result = fib(n-1) + fib(n-2) ! Any others is sum of two previous\n END SELECT\n\n ! WRITE (*,*) 'n, fib = ', n, fib_result ! Write out intermediate values\n\n END FUNCTION fib\n\nEND PROGRAM fibonacci\n", "meta": {"hexsha": "31680555f3a69d436885ac7975c2d5dd4c377e51", "size": 1376, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/basic/fibon.f90", "max_stars_repo_name": "RWTH-OS/MP-MPICH", "max_stars_repo_head_hexsha": "f2ae296477bb9d812fda587221b3419c09f85b4a", "max_stars_repo_licenses": ["mpich2"], "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/basic/fibon.f90", "max_issues_repo_name": "RWTH-OS/MP-MPICH", "max_issues_repo_head_hexsha": "f2ae296477bb9d812fda587221b3419c09f85b4a", "max_issues_repo_licenses": ["mpich2"], "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/basic/fibon.f90", "max_forks_repo_name": "RWTH-OS/MP-MPICH", "max_forks_repo_head_hexsha": "f2ae296477bb9d812fda587221b3419c09f85b4a", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-23T11:01:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-23T11:01:01.000Z", "avg_line_length": 25.4814814815, "max_line_length": 79, "alphanum_fraction": 0.4614825581, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.8032816515062915}} {"text": "program main\n implicit none\n intrinsic :: selected_real_kind, abs\n integer :: i, N\n integer, parameter :: wp = selected_real_kind(15)\n real(wp), parameter :: PI = 4.0_wp*DATAN(1.0_wp) ! exact value \n real(wp) :: sum1 = 0.0_wp, sum2 = 0.0_wp, temp\n real(wp) :: tol = 1e-6\n \n N = 1000\n\n do i = 0, N\n temp = sum1 + (-1.0_wp)**i / (2.0_wp*i + 1.0_wp) \n if ( abs(sum1 - temp) < tol ) then\n exit\n else \n sum1 = temp \n end if\n end do\n\n do i = 0, N, 2\n sum2 = sum2 + 1.0_wp / (2.0_wp*i + 1.0_wp)\n end do\n do i = 1, N, 2\n sum2 = sum2 - 1.0_wp / (2.0_wp*i + 1.0_wp)\n end do\n\n write(*, *) \"Pi (appro) = \", 4*sum1\n write(*, *) \"Pi (appro) = \", 4*sum2\n write(*, *) \"Pi (exact) = \", PI\n \nend program main\n", "meta": {"hexsha": "f57c18fce459567c09eef35c5ca257b97b22a305", "size": 738, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/fortran-exercises/ex12-pi-leibniz/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/ex12-pi-leibniz/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/ex12-pi-leibniz/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.3636363636, "max_line_length": 65, "alphanum_fraction": 0.5352303523, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517028006208, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.802859323705036}} {"text": "module running_average_module\ncontains\n function running_average(r, how_many) &\n result (arr)\n implicit none\n integer, intent(in) :: how_many\n real, intent(in), allocatable, dimension(:) :: r\n real, allocatable, dimension(:) :: arr\n integer :: i\n real :: sum = 0.\n\n allocate(arr(1:how_many))\n do i = 1, how_many\n sum = sum+r(i)\n arr(i) = sum/i\n end do\n end function\nend module\n\nmodule read_data_module\ncontains\n subroutine read_data(file_name, raw_data, &\n how_many)\n implicit none\n character(*), intent(in) :: file_name\n integer, intent(in) :: how_many\n real, intent(out), allocatable, dimension(:) :: raw_data\n integer :: i\n\n allocate(raw_data(1:how_many))\n open(1,file=file_name)\n do i = 1, how_many\n read(1,*) raw_data(i)\n end do\n end subroutine\nend module\n\nprogram ch2605\n ! Allocatable Function Results\n use running_average_module\n use read_data_module\n implicit none\n\n integer :: how_many\n character(20) :: file_name\n real, allocatable, dimension(:) :: raw_data\n real, allocatable, dimension(:) :: ra\n integer :: i\n\n print *, ' how many data items are there?'\n read *, how_many\n print *, ' what is the file name?'\n read '(a)', file_name\n call read_data(file_name,raw_data,how_many)\n allocate(ra(1:how_many))\n ra = running_average(raw_data,how_many)\n do i = 1, how_many\n print *, raw_data(i), ' ', ra(i)\n end do\nend program\n", "meta": {"hexsha": "c909d1fd067abdcd43cd8bf881a6633545a7a99b", "size": 1577, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch26/ch2605.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": "ch26/ch2605.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": "ch26/ch2605.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": 25.8524590164, "max_line_length": 64, "alphanum_fraction": 0.6011414077, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8740772368049822, "lm_q1q2_score": 0.8028226698567031}} {"text": "program main\n implicit none\n intrinsic :: selected_real_kind\n\n integer, parameter :: wp = selected_real_kind(15)\n real(wp), parameter :: PI = 4.0_wp * DATAN(1.0_wp) ! exact value \n real(wp), dimension(2) :: x\n integer :: n_in_circle = 0, n_attemps = 100000\n integer :: i\n\n do i = 1, n_attemps\n call random_number(x) ! generates a number in [0, 1)\n if ( x(1)*x(1) + x(2)*x(2) < 1) then\n n_in_circle = n_in_circle + 1\n end if\n end do\n\n write(*, *) \"Pi (appro) = \", 4 * real(n_in_circle, wp) / real(n_attemps, wp)\n write(*, *) \"Pi (exact) = \", PI\n\nend program main\n\n\n! probability of point being in circle:\n! area of circle / area of square = pi*r² / 4*r² = pi / 4\n!\n! point is in circle if x² + y² < r² (r = 1)", "meta": {"hexsha": "642fb0a72e68fdec17a9051d41cf88edd66be2ea", "size": 733, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/fortran-exercises/ex13-pi-monte-carlo/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/ex13-pi-monte-carlo/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/ex13-pi-monte-carlo/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.1481481481, "max_line_length": 78, "alphanum_fraction": 0.6152796726, "num_tokens": 261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995742876885, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.8028007201384777}} {"text": "SUBROUTINE calc_hypotenuse(side_1, side_2, hypotenuse)\nIMPLICIT NONE\n REAL, INTENT(IN) :: side_1, side_2\n REAL, INTENT(OUT) :: hypotenuse\n REAL :: temp\n\n temp = side_1**2 + side_2**2\n hypotenuse = SQRT(temp)\n\nEND SUBROUTINE calc_hypotenuse\n", "meta": {"hexsha": "3dc18d68db63d2941da92fdef4db7e6c20c65ee4", "size": 245, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/calc_hypotenuse.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/calc_hypotenuse.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/calc_hypotenuse.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": 22.2727272727, "max_line_length": 54, "alphanum_fraction": 0.7265306122, "num_tokens": 92, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813451206062, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.8027700137101764}} {"text": "program gauss_pivot\n implicit none\n real a(4,4),b(4),x(4),det \n a(1,1)=0;a(1,2)=4;a(1,3)=5;a(1,4)=2\n a(2,1)=1;a(2,2)=0;a(2,3)=2;a(2,4)=-6\n a(3,1)=4;a(3,2)=1;a(3,3)=0;a(3,4)=-2\n a(4,1)=1;a(4,2)=7;a(4,3)=1;a(4,4)=0\n b(1)=9 ;b(2) =-3;b(3) =1;b(4) =-3\n call gaussian_pivot(a,b,4,x,det)\n print *,'X=',x(1),x(2),x(3),x(4),det\nend program gauss_pivot\n\nsubroutine gaussian_pivot(a,b,n,x,det)\n implicit none\n real a(n,n),b(n),x(n),det,dd,amax\n integer n,ipv(n),i,j,k,imax,ip\n\n do i =1,n\n ipv(i)=i\n enddo\n\n ip=1\n do k=1,n-1\n amax=a(ipv(k),k)\n imax=k\n do i = k+1,n\n if (amax\n use mod_kinds, only: rk,ik,rdouble,rsingle\n use mod_constants, only: ONE\n implicit none\n\n\n\ncontains\n\n\n !> Compute and return the determinant of a 3x3 matrix.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 8/14/2017\n !!\n !!\n !----------------------------------------------------------\n function det_3x3(mat) result(det)\n real(rk), intent(in) :: mat(3,3)\n\n real(rk) :: det\n\n det = mat(1,1)*mat(2,2)*mat(3,3) - mat(1,2)*mat(2,1)*mat(3,3) - &\n mat(1,1)*mat(2,3)*mat(3,2) + mat(1,3)*mat(2,1)*mat(3,2) + &\n mat(1,2)*mat(2,3)*mat(3,1) - mat(1,3)*mat(2,2)*mat(3,1)\n\n end function det_3x3\n !**********************************************************\n\n\n\n !> Compute and return the derivative of determinant of a 3x3 matrix\n !! wrt a given differentiated matrix\n !!\n !! \\partial det(mat) / \\partial x\n !! \n !! dmat = dmat/dx\n !!\n !!\n !! @author Matteo Ugolotti\n !! @date 7/17/2018\n !!\n !!\n !----------------------------------------------------------\n function ddet_3x3(mat,dmat) result(det)\n real(rk), intent(in) :: mat(3,3)\n real(rk), intent(in) :: dmat(3,3)\n\n real(rk) :: det1, det2, det\n real(rk) :: adjugate(3,3), cofactor(3,3), temp(3,3)\n\n !\n ! Method 1 and 2 give the same result, 1 is less expensive\n !\n\n !\n ! Method 1: Direct differentiation.\n !\n !det1 = dmat(1,1)*mat(2,2)*mat(3,3) + mat(1,1)*dmat(2,2)*mat(3,3) + mat(1,1)*mat(2,2)*dmat(3,3) &\n ! - dmat(1,2)*mat(2,1)*mat(3,3) - mat(1,2)*dmat(2,1)*mat(3,3) - mat(1,2)*mat(2,1)*dmat(3,3) &\n ! - dmat(1,1)*mat(2,3)*mat(3,2) - mat(1,1)*dmat(2,3)*mat(3,2) - mat(1,1)*mat(2,3)*dmat(3,2) &\n ! + dmat(1,3)*mat(2,1)*mat(3,2) + mat(1,3)*dmat(2,1)*mat(3,2) + mat(1,3)*mat(2,1)*dmat(3,2) &\n ! + dmat(1,2)*mat(2,3)*mat(3,1) + mat(1,2)*dmat(2,3)*mat(3,1) + mat(1,2)*mat(2,3)*dmat(3,1) &\n ! - dmat(1,3)*mat(2,2)*mat(3,1) - mat(1,3)*dmat(2,2)*mat(3,1) - mat(1,3)*mat(2,2)*dmat(3,1)\n \n !\n ! Method 2: Jacobi's formula\n ! ref: https://en.wikipedia.org/wiki/Jacobi%27s_formula\n !\n\n ! Find Cofactor matrix of mat\n cofactor(1,1) = mat(2,2)*mat(3,3)-mat(2,3)*mat(3,2)\n cofactor(1,2) = -mat(2,1)*mat(3,3)+mat(2,3)*mat(3,1)\n cofactor(1,3) = mat(2,1)*mat(3,2)-mat(2,2)*mat(3,1)\n cofactor(2,1) = -mat(1,2)*mat(3,3)+mat(1,3)*mat(3,2)\n cofactor(2,2) = mat(1,1)*mat(3,3)-mat(1,3)*mat(3,1)\n cofactor(2,3) = -mat(1,1)*mat(3,2)+mat(1,2)*mat(3,1)\n cofactor(3,1) = mat(1,2)*mat(2,3)-mat(1,3)*mat(2,2)\n cofactor(3,2) = -mat(1,1)*mat(2,3)+mat(1,3)*mat(2,1)\n cofactor(3,3) = mat(1,1)*mat(2,2)-mat(1,2)*mat(2,1)\n\n ! Adjugate of mat is the transpose of cofactor of mat\n adjugate = transpose(cofactor)\n\n ! Use Jacobi's formula to find the derivative of the determinant\n temp = matmul(adjugate,dmat)\n \n ! Find the trace of temp\n det2 = temp(1,1)+temp(2,2)+temp(3,3)\n\n ! Result\n det = det2\n\n\n end function ddet_3x3\n !**********************************************************\n\n\n\n\n\n\n\n\nend module mod_determinant\n", "meta": {"hexsha": "10b1ae95a5df0b1d1e2218964711dbe079bf5034", "size": 3352, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_methods/mod_determinant.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_determinant.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_determinant.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": 31.3271028037, "max_line_length": 106, "alphanum_fraction": 0.4710620525, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.8025231089589892}} {"text": "program calc_test\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n use matrix_ops, only : init_matrix, print_matrix, print_vector\n implicit none\n integer, parameter :: M = 5, N = 5, P = 3\n real(kind=dp), dimension(M, N) :: A, B, C\n real(kind=dp), dimension(M, P) :: D\n real(kind=dp), dimension(M) :: col_max\n real(kind=dp), dimension(P) :: row_sum\n character(len=:), allocatable :: label_str\n integer :: nr_large\n\n ! initialize matrix A\n call init_matrix(A)\n label_str = \"A\"\n call print_matrix(A, label=label_str)\n\n ! initialize matrix B\n call init_matrix(B)\n label_str = \"B\"\n call print_matrix(B, label=label_str)\n\n ! matrix sum\n C = A + B\n label_str = \"A + B\"\n call print_matrix(C, label=label_str)\n\n ! element-wise product\n C = A * B\n label_str = \"A * B\"\n call print_matrix(C, label=label_str)\n\n ! element-wise division\n C = A/B\n label_str = \"A/B\"\n call print_matrix(C, label=label_str)\n\n ! element-wise power\n C = A**2\n label_str = \"A**2\"\n call print_matrix(C, label=label_str)\n\n ! matrix product\n C = matmul(A, B)\n label_str = \"A . B\"\n call print_matrix(C, label=label_str)\n\n ! element-wise addition of constant\n C = 2.0_dp + A\n label_str = \"2 + A\"\n call print_matrix(C, label=label_str)\n\n ! element-wise multiplication of constant\n C = 3.0_dp*A\n label_str = \"3*A\"\n call print_matrix(C, label=label_str)\n\n ! initialize matrix D\n call init_matrix(D)\n label_str = \"D\"\n call print_matrix(D, label=label_str)\n\n ! row sum\n row_sum = sum(D, dim=1)\n label_str = 'row sum D'\n call print_vector(row_sum, label=label_str)\n\n ! column maximum\n col_max = maxval(D, dim=2)\n label_str = 'column max D'\n call print_vector(col_max, label=label_str)\n\n ! number of elements larger than 0.5\n nr_large = count(D > 0.5)\n label_str = 'number elements D > 0.5'\n print '(A, \": \", I0)', label_str, nr_large\n\n ! check whether any element < 0.01\n if (any(D < 0.01)) then\n print *, 'Some elements < 0.01'\n else\n print *, 'no elements < 0.01'\n end if\n\nend program calc_test\n\n", "meta": {"hexsha": "79ca5fcad3ca192c33d53a49855e4aa7f661d322", "size": 2170, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Matrices/calc_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/Matrices/calc_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/Matrices/calc_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": 24.9425287356, "max_line_length": 66, "alphanum_fraction": 0.6165898618, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8652240912652671, "lm_q1q2_score": 0.8023770630117532}} {"text": "PROGRAM Test_Prime_Utility\n USE Prime_Utility\n IMPLICIT NONE\n ! Parameters\n INTEGER, PARAMETER :: NTEST=500\n INTEGER, PARAMETER :: NPFTEST=9438\n ! Variables\n INTEGER :: i, j, errStatus, test_number\n INTEGER :: prod\n TYPE(Prime_type) :: Prime\n\n WRITE(*,'(/5x,\"Primes in range 1..\",i0,\" derived via IsPrime:\")') NTEST\n j=0\n DO i = 1, NTEST\n IF (IsPrime(i)) THEN\n j=j+1\n IF(MOD(j-1,10)==0 .AND. j/=1) WRITE(*,*)\n WRITE(*,'(1x,i5)',ADVANCE='NO') i\n END IF\n END DO\n\n Prime=Primes(NTEST)\n WRITE(*,'(//5x,\"Primes in range 1..\",i0,\" derived via Primes:\")') Prime%number\n WRITE(*,'(10(1x,i5))') Prime%n\n errStatus = Destroy_Prime(Prime)\n\n Prime=PrimeFactor(NPFTEST)\n CALL Display_Primes()\n errStatus = Destroy_Prime(Prime)\n \n Test_Loop: DO\n WRITE( *,FMT='(//5x,\"Enter integer number to test [-ve to quit]: \")',ADVANCE='NO' )\n READ(*,*) test_number\n IF ( test_number < 0 ) EXIT Test_Loop\n Prime=PrimeFactor(test_number)\n CALL Display_Primes()\n errStatus = Destroy_Prime(Prime)\n END DO Test_Loop\n \nCONTAINS\n\n SUBROUTINE Display_Primes()\n WRITE(*,'(/5x,\"Prime factors for \",i0,\":\")') Prime%number\n prod=1\n DO i=1,Prime%nPrimes\n prod=prod*(Prime%n(i)**Prime%nExp(i))\n WRITE(*,'(i0,\"^\",i0)',ADVANCE='NO') Prime%n(i), Prime%nExp(i)\n IF(i < Prime%nPrimes) WRITE(*,'(\" x \")',ADVANCE='NO')\n END DO\n WRITE(*,'(\" = \",i0)')prod\n END SUBROUTINE Display_Primes\n \nEND PROGRAM Test_Prime_Utility\n", "meta": {"hexsha": "5bb548be55ffc4f3a001b442a4336fe8ca8c9543", "size": 1467, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/FFT_Utility/Prime_Utility/Test/Test_Prime_Utility.f90", "max_stars_repo_name": "hsbadr/crtm", "max_stars_repo_head_hexsha": "bfeb9955637f361fc69fa0b7af0e8d92d40718b1", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-11-19T10:00:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T02:42:18.000Z", "max_issues_repo_path": "src/Utility/FFT_Utility/Prime_Utility/Test/Test_Prime_Utility.f90", "max_issues_repo_name": "hsbadr/crtm", "max_issues_repo_head_hexsha": "bfeb9955637f361fc69fa0b7af0e8d92d40718b1", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-11-05T21:04:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T18:23:10.000Z", "max_forks_repo_path": "src/Utility/FFT_Utility/Prime_Utility/Test/Test_Prime_Utility.f90", "max_forks_repo_name": "hsbadr/crtm", "max_forks_repo_head_hexsha": "bfeb9955637f361fc69fa0b7af0e8d92d40718b1", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2020-10-29T17:54:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T08:42:45.000Z", "avg_line_length": 27.1666666667, "max_line_length": 87, "alphanum_fraction": 0.6278118609, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.8023731125910422}} {"text": "SUBROUTINE phi_linear_3D_standing(H,angle,Lx,Ly,xc,yc,z,d,omega,time,grav,phix,phiy,phiz,phi,phit)\n!\nUSE Precision\nUSE Constants\nIMPLICIT NONE\n!\nREAL(KIND=long), INTENT(IN) :: H,Lx,Ly,xc,yc,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!\nREAL(KIND=long) :: HH,k,w,g,c,angle,x,y,tmp\n!\nx = xc*COS(-angle)-yc*SIN(-angle)\ny = xc*SIN(-angle)+yc*COS(-angle)\n\ng = grav\nkx = two*pi/Lx; ky = two*pi/Ly\nk = SQRT(kx**2+ky**2)\nw = omega\nc = SQRT(g/k*TANH(k*d))\nHH = H\n\nphix = kx*half*HH*c*COSH(k*(z+d))/SINH(k*d)*SIN(w*time)*SIN(kx*X)*COS(ky*Y)\nphiy = ky*half*HH*c*COSH(k*(z+d))/SINH(k*d)*SIN(w*time)*COS(kx*X)*SIN(ky*Y)\nphiz = -half*k*HH*c*SINH(k*(z+d))/SINH(k*d)*SIN(w*time)*COS(kx*X)*COS(ky*Y)\n!\nIF(present(phit)) THEN\n phit = -half*w*HH*c*COSH(k*(z+d))/SINH(k*d)*COS(w*time)*COS(kx*X)*COS(ky*Y)\nENDIF\nIF(present(phi)) THEN\n phi = -half*HH*c*COSH(k*(z+d))/SINH(k*d)*SIN(w*time)*COS(kx*X)*COS(ky*Y)\nENDIF\n!\ntmp = phix\nphix = tmp*COS(angle)-phiy*SIN(angle)\nphiy = tmp*SIN(angle)+phiy*COS(angle)\n!\n!xc = x*COS(angle)-y*SIN(angle)\n!yc = x*SIN(angle)+y*COS(angle)\n\nEND SUBROUTINE phi_linear_3D_standing\n", "meta": {"hexsha": "3dcc5447a3f3ea3b8aeaaa9446b0a13395c702fe", "size": 1343, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/phi_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/phi_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/phi_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": 29.8444444444, "max_line_length": 98, "alphanum_fraction": 0.6492926284, "num_tokens": 586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811581728097, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.8023698381487409}} {"text": "program pi\n implicit none\n integer::in_circle,i,j,n,m\n real::x,y,value\n\n n=1000\n m=100000\n do j=1,n\n in_circle=0\n do i=1,m\n call random_number(x) ! generating random points in the square\n call random_number(y)\n if ((x**2+y**2).le.1) then !check if point lies inside circle, and count if it does\n in_circle=in_circle+1\n endif\n enddo\n value=value+(in_circle*1.00/i)*4 !taking average over multiple runs\n enddo\n print*,\"Estimated value of pi by\",n*m/1000,\"k iterations = \",value/n*1.0\nend program pi", "meta": {"hexsha": "f1715b31f887d75d29ba2aa573f215ed33bb9128", "size": 607, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pi.f90", "max_stars_repo_name": "ShrirajHegde/Pi_Monte-Carlo", "max_stars_repo_head_hexsha": "a296fca63f0f968746a3d520d9f90df2b44c513c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-10T05:11:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T05:11:44.000Z", "max_issues_repo_path": "pi.f90", "max_issues_repo_name": "ShrirajHegde/Pi_Monte-Carlo", "max_issues_repo_head_hexsha": "a296fca63f0f968746a3d520d9f90df2b44c513c", "max_issues_repo_licenses": ["MIT"], "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": "ShrirajHegde/Pi_Monte-Carlo", "max_forks_repo_head_hexsha": "a296fca63f0f968746a3d520d9f90df2b44c513c", "max_forks_repo_licenses": ["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.35, "max_line_length": 95, "alphanum_fraction": 0.5914332784, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122684798184, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.8023664372591265}} {"text": "C$Procedure UNORMG ( Unit vector and norm, general dimension )\n \n SUBROUTINE UNORMG ( V1, NDIM, VOUT, VMAG )\n \nC$ Abstract\nC\nC Normalize a double precision vector of arbitrary dimension and\nC return its magnitude.\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 DOUBLE PRECISION VOUT ( NDIM )\n DOUBLE PRECISION VMAG\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I Vector to be normalized.\nC NDIM I Dimension of V1 (and also VOUT).\nC VOUT O Unit vector V1 / |V1|.\nC If V1 = 0, VOUT will also be zero.\nC VMAG O Magnitude of V1, that is, |V1|.\nC\nC$ Detailed_Input\nC\nC V1 This variable may contain any vector of arbitrary\nC dimension, including the zero vector.\nC NDIM This is the dimension of V1 and VOUT.\nC\nC$ Detailed_Output\nC\nC VOUT This variable contains the unit vector in the direction\nC of V1. If V1 is the zero vector, then VOUT will also be\nC the zero vector.\nC VMAG This is the magnitude of V1.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC UNORMG references a function called VNORMG (which itself is\nC numerically stable) to calculate the norm of the input vector V1.\nC If the norm is equal to zero, then each component of the output\nC vector VOUT is set to zero. Otherwise, VOUT is calculated by\nC dividing V1 by the norm. No error detection or correction is\nC implemented.\nC\nC$ Examples\nC\nC The following table shows how selected V1 implies VOUT and MAG.\nC\nC V1 NDIM VOUT MAG\nC --------------------------------------------------------\nC (5, 12) 2 (5/13, 12/13) 13\nC (1D-7, 2D-7, 2D-7) 3 (1/3, 2/3, 2/3) 3D-7\nC\nC$ Restrictions\nC\nC No error checking is implemented in this subroutine to guard\nC against numeric overflow.\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.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 n-dimensional unit vector and norm\nC\nC-&\n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 10-JAN-1989 (WLT)\nC\nC Error free specification added.\nC\nC-&\n DOUBLE PRECISION VNORMG\n INTEGER I\nC\nC Obtain the magnitude of V1\nC\n VMAG = VNORMG (V1,NDIM)\nC\nC If VMAG is nonzero, then normalize. Note that this process is\nC numerically stable: overflow could only happen if VMAG were small,\nC but this could only happen if each component of V1 were also small.\nC In fact, the magnitude of any vector is never less than the\nC magnitude of any component.\nC\n IF (VMAG.GT.0.D0) THEN\n DO I = 1, NDIM\n VOUT(I) = V1(I) / VMAG\n END DO\n ELSE\n DO I = 1, NDIM\n VOUT(I) = 0.D0\n END DO\n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "94eca98a4492107781a5b7372091cf3b256d66ac", "size": 4883, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/unormg.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/unormg.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/unormg.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.5555555556, "max_line_length": 71, "alphanum_fraction": 0.6387466721, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122708828602, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.8023664334476216}} {"text": "! Created by on 09.03.2020.\r\nrecursive function lagger_polynomial(x, n, alpha) result(y)\r\n implicit none\r\n real :: x\r\n integer :: n\r\n real :: alpha\r\n real :: y\r\n if (n==0) then\r\n y = 1\r\n else if (n==1) then\r\n y = 1 + alpha - x\r\n else\r\n y = ((2 * n + alpha - 1 - x) * lagger_polynomial(x, n - 1, alpha) - (n + alpha - 1) * &\r\n lagger_polynomial(x, n - 2, alpha)) / n\r\n end if\r\nend function lagger_polynomial\r\n\r\nfunction radial_function(r, tilde_omega, n, l) result (y)\r\n implicit none\r\n real :: r, tilde_omega, y, tilde_r, exponent\r\n real, external :: lagger_polynomial\r\n integer :: n, l, lagger_n, lagger_l\r\n lagger_n = (n - l) / 2\r\n lagger_l = l + 0.5\r\n if (l == 0) then\r\n tilde_r = 1\r\n else\r\n tilde_r = (sqrt(tilde_omega) * r)**l\r\n end if\r\n y = (-1)**((n - l) / 2.0) * (tilde_omega)**(3.0 / 4.0) * &\r\n sqrt((2.0 * gamma((n + l) / 2.0d0)) / gamma((n + l) / 2.0d0 + 3.0 / 2.0)) * &\r\n tilde_r * exp(-0.5 * tilde_omega * r**2) * &\r\n lagger_polynomial(tilde_omega * r**2, lagger_n, lagger_l)\r\nend function radial_function", "meta": {"hexsha": "356379500f89f11a07e02ae27c83e3f4b7cfb6c0", "size": 1159, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/radial.f90", "max_stars_repo_name": "rlmacen/sphere", "max_stars_repo_head_hexsha": "23d052500d26f55d9acfbca6f0d56ecf75d01c55", "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/radial.f90", "max_issues_repo_name": "rlmacen/sphere", "max_issues_repo_head_hexsha": "23d052500d26f55d9acfbca6f0d56ecf75d01c55", "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/radial.f90", "max_forks_repo_name": "rlmacen/sphere", "max_forks_repo_head_hexsha": "23d052500d26f55d9acfbca6f0d56ecf75d01c55", "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": 34.0882352941, "max_line_length": 96, "alphanum_fraction": 0.5211389129, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191297273498, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.8022139251149453}} {"text": "!--------------------------------------------------------------------------------------------------\n! MODULE: math_mod\n!> @author Marin Sapunar, Ruđer Bošković Institute\n!> @date March, 2019\n!--------------------------------------------------------------------------------------------------\nmodule math_mod\n use global_defs\n implicit none\n\n\n private\n public :: factorial\n public :: factorial2\n public :: binomial\n\n\ncontains\n\n\n !----------------------------------------------------------------------------------------------\n ! FUNCTION: factorial\n !> @brief Product of all numbers up to n (n!).\n !----------------------------------------------------------------------------------------------\n elemental function factorial(n)\n integer, intent(in) :: n\n integer(j15) :: factorial\n integer(j15), parameter :: fact(0:14) = [ &\n & 1_j15, 1_j15, 2_j15, 6_j15, &\n & 24_j15, 120_j15, 720_j15, 5040_j15, &\n & 40320_j15, 362880_j15, 3628800_j15, 39916800_j15, &\n & 479001600_j15, 6227020800_j15, 87178291200_j15 &\n & ]\n factorial = fact(n)\n end function factorial\n\n\n !----------------------------------------------------------------------------------------------\n ! FUNCTION: factorial2\n !> @brief Product of all odd/even numbers up to n (n!!).\n !----------------------------------------------------------------------------------------------\n elemental function factorial2(n)\n integer, intent(in) :: n\n integer(j15) :: factorial2\n integer(j15), parameter :: dfact(-1:14) = [ &\n & 1_j15, 1_j15, 1_j15, 2_j15, &\n & 3_j15, 8_j15, 15_j15, 48_j15, &\n & 105_j15, 384_j15, 945_j15, 3840_j15, &\n & 10395_j15, 46080_j15, 135135_j15, 645120_j15 &\n & ]\n factorial2 = dfact(n)\n end function factorial2\n\n\n !----------------------------------------------------------------------------------------------\n ! FUNCTION: binomial\n !> @brief Binomial coefficient for n over m.\n !----------------------------------------------------------------------------------------------\n function binomial(n, m)\n integer, intent(in) :: n\n integer, intent(in) :: m\n integer(j15) :: binomial\n if (m < 0) then\n binomial = 0\n else if (m > n) then\n binomial = 0\n else\n binomial = factorial(n) / factorial(m) / factorial(n-m)\n end if\n end function binomial\n\n\nend module math_mod\n", "meta": {"hexsha": "cc515080566d26713f5d871bc650337c54cb75fd", "size": 3096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/util_fort/math_mod.f90", "max_stars_repo_name": "marin-sapunar/cis_nto", "max_stars_repo_head_hexsha": "a13492d3e518e4252909c7dd11f13e492ddab124", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-08T16:45:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-08T16:45:16.000Z", "max_issues_repo_path": "src/util_fort/math_mod.f90", "max_issues_repo_name": "marin-sapunar/cis_nto", "max_issues_repo_head_hexsha": "a13492d3e518e4252909c7dd11f13e492ddab124", "max_issues_repo_licenses": ["MIT"], "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_fort/math_mod.f90", "max_forks_repo_name": "marin-sapunar/cis_nto", "max_forks_repo_head_hexsha": "a13492d3e518e4252909c7dd11f13e492ddab124", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.4109589041, "max_line_length": 100, "alphanum_fraction": 0.3226744186, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.8022139142470475}} {"text": "C$Procedure PRODAI ( Product of an integer array )\n \n INTEGER FUNCTION PRODAI ( ARRAY, N )\n \nC$ Abstract\nC\nC Return the product of the elements of an integer array.\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 ARRAY, MATH, UTILITY\nC\nC$ Declarations\n \n INTEGER ARRAY ( * )\n INTEGER N\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC ARRAY I Input array.\nC N I Number of elements in ARRAY.\nC PRODAI O Product of the elements of ARRAY.\nC\nC$ Detailed_Input\nC\nC ARRAY is the input array.\nC\nC N is the number of elements in the array.\nC\nC$ Detailed_Output\nC\nC PRODAI is the product of the elements of the input array.\nC That is,\nC\nC PRODAI = ARRAY(1) * ARRAY(2) * ... * ARRAY(N)\nC\nC If N is zero or negative, PRODAI is one.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC The value of the function is initially set to one. The elements\nC of the array are then multiplied. If the number of elements is\nC zero or negative, PRODAI is one.\nC\nC$ Examples\nC\nC Let ARRAY contain the following elements.\nC\nC ARRAY(1) = 12\nC ARRAY(2) = 2\nC ARRAY(3) = 4\nC ARRAY(4) = 75\nC ARRAY(5) = 18\nC\nC Then\nC\nC PRODAI ( ARRAY, -3 ) = 1\nC PRODAI ( ARRAY, 0 ) = 1\nC PRODAI ( ARRAY, 1 ) = 12\nC PRODAI ( ARRAY, 2 ) = 24\nC PRODAI ( ARRAY, 5 ) = 129600\nC PRODAI ( ARRAY(3), 3 ) = 5400\nC\nC\nC$ Restrictions\nC\nC PRODAI does not check for overflow. (For integers, this can\nC occur relatively quickly.)\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC I.M. Underwood (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 (IMU)\nC\nC-&\n \nC$ Index_Entries\nC\nC product of an integer array\nC\nC-&\n \n \n \n \nC\nC Local variables\nC\n INTEGER PROD\n INTEGER I\n \n \nC\nC Begin at one.\nC\n PROD = 1\n \nC\nC Multiply the elements. If N is zero or negative, nothing happens.\nC\n DO I = 1, N\n PROD = PROD * ARRAY(I)\n END DO\n \nC\nC Return the product.\nC\n PRODAI = PROD\n \n RETURN\n END\n", "meta": {"hexsha": "9757b4feff0f051bf9a2eeb3c808cabc10ef440a", "size": 4016, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/prodai.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/prodai.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/prodai.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": 24.0479041916, "max_line_length": 72, "alphanum_fraction": 0.6080677291, "num_tokens": 1192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.8022074616215977}} {"text": "submodule (m_maths) sm_maths_r1d\n !! Implement math routines for double precision arrays\nimplicit none\n\ncontains\n !====================================================================!\n module function crossproduct_r1D(a,b) result(res)\n !! Interfaced with crossproduct()\n !====================================================================!\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 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\n !====================================================================!\n !====================================================================!\n module function cumprod_r1D(this) result(res)\n !! Interfaced with cumprod()\n !====================================================================!\n real(r32),intent(in) :: this(:) !! 1D array\n real(r32) :: res(size(this)) !! Cumulative product\n integer(i32) :: i\n integer(i32) :: N\n N=size(this)\n res(1) = this(1)\n do i=2,N\n res(i) = res(i-1) * this(i)\n end do\n end function\n !====================================================================!\n !====================================================================!\n module function cumsum_r1D(this) result(res)\n !! Interfaced with cumsum()\n !====================================================================!\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32) :: res(size(this)) !! Cumulative sum\n integer(i32) :: i\n integer(i32) :: N\n N=size(this)\n res(1) = this(1)\n do i=2,N\n res(i) = res(i-1) + this(i) ! Round off error?\n end do\n end function\n !====================================================================!\n !====================================================================!\n module function geometricMean_r1D(this) result(res)\n !! Interfaced with geometricMean()\n !====================================================================!\n real(r32),intent(in) :: this(:)\n real(r64) :: res\n res=product(this)\n res=res**(dble(size(this)))\n end function\n !====================================================================!\n !====================================================================!\n module procedure Mean_r1D\n !! interface with mean()\n !====================================================================!\n !module function mean_r1D(this) result(res)\n !real(r32) :: this(:)\n !real(r64) :: res\n res=sum(dble(this))/(dble(size(this)))\n end procedure\n !====================================================================!\n !====================================================================!\n module function median_r1D(this) result(res)\n !====================================================================!\n !! Interfaced with median()\n real(r32), intent(in) :: this(:) !! 1D array\n real(r32) :: res !! median\n integer(i32), allocatable :: i(:)\n integer(i32) :: iMed\n integer(i32) :: N\n\n integer(i32) :: iTmp\n\n N=size(this)\n call allocate(i,N)\n call arange(i,1,N)\n\n if (mod(N,2)==0) then\n iMed = N/2\n call argSelect(this, i, iMed, iTmp)\n res=this(iTmp)\n call arange(i,1,N)\n call argSelect(this, i, iMed+1, iTmp)\n res=0.5*(res+this(iTmp))\n else\n iMed=N/2 + 1\n call argSelect(this, i, iMed, iTmp)\n res = this(iTmp)\n end if\n\n deallocate(i)\n end function\n !====================================================================!\n !====================================================================!\n module procedure norm1_r1D\n !! interface with norm1()\n !====================================================================!\n !module function norm1_d1D(this) result(res)\n !real(r32) :: this(:)\n !real(r32) :: res\n res=sum(abs(this))\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure normI_r1D\n !! interface with normI()\n !====================================================================!\n !module function normI_d1D(this) result(res)\n !real(r32) :: this(:)\n !real(r32) :: res\n res=maxval(abs(this))\n end procedure\n !====================================================================!\n !====================================================================!\n module function project_r1D(a,b) result(c)\n !! Interfaced with project()\n !====================================================================!\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! real(r64) :: c1\n ! Normalize b\n! c1=norm2(b)**2.d0\n! if (c1 == 0.0) then\n! c=0.d0\n! return\n! end if\n! c=b/c1\n! ! Dot a onto b hat\n! c1=dot_product(a,b)\n! ! Multiply projected length by b hat\n! c=c1*c\n c = real(project(dble(a),dble(b)), kind=r32)\n end function\n !====================================================================!\n\n !====================================================================!\n module procedure trimmedmean_r1D\n !! Interfaced with trimmedmean()\n !====================================================================!\n !function trimmedmean_r1D(this,alpha) result(res)\n !real(r32) :: this(:)\n !real(r64) :: alpha\n !real(r64) :: res\n integer(i32) :: istat\n integer(i32) :: j\n integer(i32) :: N\n integer(i32) :: tmp\n integer(i32), allocatable :: i(:)\n real(r32) :: alpha_\n\n real(r32), allocatable :: rTmp(:)\n\n N=size(this)\n alpha_=alpha*0.01\n ! Test the percentage\n if (alpha_ <= 0.0) then\n res=Mean(this)\n return\n elseif (alpha_ >= 0.5) 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(rTmp, N-(2*tmp))\n rTmp =this(i(tmp+1:N-tmp))\n res=mean(rTmp)\n call deallocate(i)\n call deallocate(rTmp)\n\n end procedure\n !====================================================================!\n\n !====================================================================!\n module procedure std_r1D\n !! Interfaced with std()\n !====================================================================!\n !real(r32) :: this(:)\n !real(r64) :: res\n res=dsqrt(Variance(this))\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure Variance_r1D\n !! Interfaced with variance()\n !====================================================================!\n !real(r32) :: 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 !====================================================================!\nend submodule\n", "meta": {"hexsha": "8ad9e4a75cad6ed51b73d1d897a17850463acc66", "size": 6963, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths/sm_maths_r1D.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_r1D.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_r1D.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.3157894737, "max_line_length": 72, "alphanum_fraction": 0.3929340801, "num_tokens": 1695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.8022074602303116}} {"text": "double precision function mean(a, n)\n double precision, intent(in) :: a(n)\n integer i\n mean = 0\n do i=1, n\n mean = mean + a(i)\n enddo\n mean = mean/n\nend function mean\n\ndouble precision function stddev(a, n)\n double precision, intent(in) :: a(n)\n double precision mu, mean\n integer i\n mu = mean(a, n)\n stddev = 0\n do i=1, n\n stddev = stddev + (a(i)-mu)**2\n enddo\n stddev = sqrt(stddev/(n-1))\nend function stddev\n\ndouble precision function corr(a, n)\n double precision, intent(in) :: a(n)\n double precision mu, sig, mean, stddev, ct\n integer i, k\n mu = mean(a, n)\n sig = stddev(a, n)\n if (abs(sig)> 1994-10-20 DRANE Krogh Changes to use M77CON\nc>> 1994-06-24 DRANE 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 DGFLAG 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 DRANE 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 DRANE = -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--D replaces \"?\": ?RANE, ?RANUA, RANC?1, RANC?2, ?PTR, ?NUMS, ?GFLAG\nC RANCD1 and RANCD2 are common blocks.\nc Calls RAN0 to initialize DPTR and DGFLAG.\nc ------------------------------------------------------------------\n integer M\n parameter(M = 97)\n double precision DNUMS(M), STDDEV\n common/RANCD2/DNUMS\n integer DPTR\n logical DGFLAG\n common/RANCD1/DPTR, DGFLAG\n save /RANCD1/, /RANCD2/, FIRST\n logical FIRST\n data FIRST / .true. /\nc ------------------------------------------------------------------\n if(FIRST) then\n FIRST = .false.\n call RAN0\n endif\nc\n DPTR = DPTR - 1\n if(DPTR .eq. 0) then\n call DRANUA(DNUMS, M)\n DPTR = M\n endif\n DRANE = -STDDEV * log(DNUMS(DPTR))\n return\n end\n", "meta": {"hexsha": "18223423af01420cd85bdc913c78fb63b32df7c5", "size": 2150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/drane.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/drane.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/drane.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.5804651163, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.8020841562854213}} {"text": "module mod_fft\r\n use kind_m\r\n implicit none\r\n private\r\n public :: init_fft, fft23, fft23han ! subroutines\r\n integer, save, public :: indx576(1152), indx192(384)\r\n complex (kind = kd), save, public :: omega576(0:1151), omega192(0:383), sqrt3_2\r\n real (kind = kd), save, public :: han576(1152), han192(384)\r\n real (kind = kd), save :: pi\r\ncontains\r\n !-----------------------------------------------------------------------------------------------------------------\r\n subroutine init_fft\r\n integer :: i, k, n, m\r\n pi = 4.0_kd * atan(1.0_kd)\r\n sqrt3_2 = cmplx(0.0_kd, sqrt(0.75_kd), kind = kd) ! isqrt(3) / 2\r\n indx576 = 1\r\n do i = 1, 1152 !2^7 3^2\r\n do k = 1, 7\r\n n = 2**(k - 1)\r\n m = 1152 / 2**k\r\n indx576(i) = indx576(i) + ( mod(i - 1, 2 * m) / m ) * n\r\n end do\r\n do k = 1, 2\r\n n = 2**7 * 3**(k - 1) \r\n m = 1152 / 2**7 / 3**k\r\n indx576(i) = indx576(i) + ( mod(i - 1, 3 * m) / m ) * n\r\n end do\r\n omega576(i - 1) = exp( cmplx(0.0_kd, 2.0_kd * pi / 1152.0_kd * real(i - 1, kind = kd), kind = kd) )\r\n !han576(i) = sqrt(8.0d0 / 3.0d0) * 0.5d0 * ( 1.0d0 - cos(2.0d0 * pi * real(i - 1, kind = 8) / 1152.0d0 ) )\r\n han576(i) = 0.5_kd * ( 1.0_kd - cos(2.0_kd * pi * real(i - 1, kind = 8) / 1152.0_kd ) )\r\n end do\r\n ! \r\n indx192 = 1\r\n do i = 1, 192\r\n do k = 1, 7\r\n n = 2**(k - 1)\r\n m = 384 / 2**k\r\n indx192(i) = indx192(i) + ( mod(i - 1, 2 * m) / m ) * n\r\n end do\r\n do k = 1, 1\r\n n = 2**7 * 3**(k - 1) \r\n m = 384 / 2**7 / 3**k\r\n indx192(i) = indx192(i) + ( mod(i - 1, 3 * m) / m ) * n\r\n end do\r\n omega192(i - 1) = exp( cmplx(0.0_kd, 2.0_kd * pi / 384.0_kd * real(i - 1, kind = kd), kind = kd) )\r\n !han192(i) = sqrt(8.0d0 / 3.0d0) * 0.5d0 * ( 1.0d0 - cos(2.0d0 * pi * real(i - 1, kind = 8) / 384.0d0 ) )\r\n han192(i) = 0.5_kd * ( 1.0_kd - cos(2.0_kd * pi * real(i - 1, kind = kd) / 384.0_kd ) )\r\n end do\r\n end subroutine init_fft\r\n !-----------------------------------------------------------------------------------------------------------------\r\n subroutine fft23(np2, np3, indx, omega, fft)\r\n integer , intent(in ) :: np2, np3, indx(:)\r\n complex (kind = kd), intent(in ) :: omega(0:)\r\n complex (kind = kd), intent(in out) :: fft(:)\r\n complex (kind = kd) :: c1, c2, c3, c4, tmp1, tmp2, tmp3\r\n integer :: i, j, nn, iphase1, iphase2, m1, m2, m3, k3, kn3, k2, kn2\r\n nn = 2**np2 * 3**np3\r\n fft = fft(indx) / real(nn, kind = kd) ! reorder and normalize\r\n ! 3**np3\r\n do k3 = 1, np3 ! 3^n (n=2)\r\n kn3 = 3**(k3 - 1)\r\n do i = 1, nn, 3 * kn3 \r\n do j = 1, kn3\r\n iphase1 = 2**np2 * 3**(np3 - k3) * (j - 1) \r\n iphase2 = 2 * iphase1\r\n c1 = omega( mod(iphase1, nn) )\r\n c2 = omega( mod(iphase2, nn) )\r\n m1 = i + j - 1\r\n m2 = m1 + kn3\r\n m3 = m2 + kn3\r\n tmp1 = fft(m1)\r\n tmp2 = c1 * fft(m2)\r\n tmp3 = c2 * fft(m3)\r\n fft(m1) = tmp1 + tmp2 + tmp3\r\n c3 = tmp1 - 0.5_kd * ( tmp2 + tmp3 )\r\n c4 = sqrt3_2 * ( tmp2 - tmp3 ) ! sqrt3_2 = i sqrt(3) / 2\r\n fft(m2) = c3 + c4\r\n fft(m3) = c3 - c4\r\n end do\r\n end do\r\n end do\r\n ! 2**np2\r\n do k2 = 1, np2\r\n kn2 = 2**(k2 - 1) * 3**np3\r\n do i = 1, nn, 2 * kn2\r\n do j = 1, kn2 \r\n iphase1 = 2**(np2 - k2) * (j - 1) \r\n c1 = omega( mod(iphase1, nn) )\r\n m1 = i + j - 1\r\n m2 = m1 + kn2\r\n tmp2 = c1 * fft(m2)\r\n fft(m2) = fft(m1) - tmp2\r\n fft(m1) = fft(m1) + tmp2\r\n end do\r\n end do\r\n end do\r\n end subroutine fft23\r\n !-----------------------------------------------------------------------------------------------------------------\r\n subroutine fft23han(np2, np3, indx, omega, fft, han)\r\n integer , intent(in ) :: np2, np3, indx(:)\r\n complex (kind = kd), intent(in ) :: omega(0:)\r\n complex (kind = kd), intent(in out) :: fft(:)\r\n real (kind = kd), intent(in ) :: han(:)\r\n fft = fft * han\r\n call fft23(np2, np3, indx, omega, fft)\r\n end subroutine fft23han\r\n !-----------------------------------------------------------------------------------------------------------------\r\nend module mod_fft", "meta": {"hexsha": "273a5b8072b007bd75253bea5a9b27f257bd9e70", "size": 4969, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft.f90", "max_stars_repo_name": "cure-honey/uzura3_fpm", "max_stars_repo_head_hexsha": "ff2cb6ff2195e307da61454762b5e7e39e504895", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-11T15:02:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T15:02:44.000Z", "max_issues_repo_path": "src/fft.f90", "max_issues_repo_name": "cure-honey/uzura3_fpm", "max_issues_repo_head_hexsha": "ff2cb6ff2195e307da61454762b5e7e39e504895", "max_issues_repo_licenses": ["MIT"], "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/fft.f90", "max_forks_repo_name": "cure-honey/uzura3_fpm", "max_forks_repo_head_hexsha": "ff2cb6ff2195e307da61454762b5e7e39e504895", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.0092592593, "max_line_length": 119, "alphanum_fraction": 0.3531897766, "num_tokens": 1667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.8020471638257834}} {"text": "module procedures\nimplicit none\ncontains\n\n!----------------------------\n! Functions to solve:\n!----------------------------\n\nreal(kind=8) function f1(x)\n real(kind=8), intent (in) :: x\n\n f1 = (cos(x))**3\nend function f1\n\nreal(kind=8) function f2(x)\n real(kind=8), intent(in) :: x\n\n f2 = 1/(1+9.0d0*x*x)\nend function f2\n\n!----------------------------\n! Integration routine:\n!----------------------------\n\nsubroutine I_Simpsons38 (Fun, a, b, I_new)\n\n real(kind=8), intent(in) :: a, b\n real(kind=8), intent(out) :: I_new\n interface\n real(kind=8) function Fun(z)\n real(kind=8), intent (in) :: z\n end function\n end interface\n real(kind=8), allocatable, dimension(:) :: x, fx\n real(kind=8) :: error, I_old, h\n integer :: n, i, j, counts\n\n write(*,*)\n write(*,*) 'iteration integral error'\n write(*,*) '---------------------------------------------'\n\n !--------------------------------\n ! The first step:\n !--------------------------------\n\n n = 3 ! number of intervals \n h = (b-a)/n ! length of interval\n\n ! Determine the values of xi and f(xi) for every interval:\n allocate (x(n+1), fx(n+1))\n x(1) = a\n do i = 2, n+1\n x(i) = x(i-1) + h\n fx(i) = Fun(x(i))\n end do\n\n ! Determine the integral:\n I_old = fx(1) + fx(n+1)\n do i = 2, n-1, 3\n I_old = I_old + 3.0d0*(fx(i) + fx(i+1))\n end do\n do i = 4, n-2, 3\n I_old = I_old + 2.0d0*fx(i)\n end do\n I_old = I_old*((3.0d0*h)/8.0d0)\n deallocate (x, fx)\n\n !--------------------------------\n ! All the other steps:\n !--------------------------------\n\n counts = 0\n error = 1\n do while ((counts .le. 20) .and. (error .ge. 0.001)) \n n = 2*n ! number of intervals \n h = (a-b)/n ! length of interval\n\n ! Determine the values of xi and f(xi) for every interval:\n allocate (x(n+1), fx(n+1))\n x(1) = a\n do i = 2, n+1\n x(i) = x(i-1) + h\n fx(i) = Fun(x(i))\n end do\n\n ! Determine the integral:\n I_new = fx(1) + fx(n+1)\n do i = 2, n-1, 3\n I_new = I_new + 3.0d0*(fx(i) + fx(i+1))\n end do\n do i = 4, n-2, 3\n I_new = I_new + 2.0d0*fx(i)\n end do\n I_new = I_new*((3.0d0*h)/8.0d0)\n\n ! Convergence criteria:\n error = dabs((I_new-I_old)/I_old)\n I_old = I_new\n write(*,'(I5,2F20.5)') counts, I_new, error\n counts = counts + 1\n deallocate (x, fx)\n end do\n\nend subroutine I_Simpsons38\n\nend module procedures\n", "meta": {"hexsha": "db5060019c53f428d89ce864a49ca0ed95b6993b", "size": 2486, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW8/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/HW8/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/HW8/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": 23.2336448598, "max_line_length": 64, "alphanum_fraction": 0.4662107804, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.8019611493015091}} {"text": "! ARPIT KUMAR JAIN Roll No - 180122009\nPROGRAM Arpit\n IMPLICIT NONE\n\n REAL, PARAMETER :: pi = acos(-1.0)\n REAL:: x, x0, delta, k0, u, Etrans\n INTEGER:: i, outunit\n COMPLEX:: iota, Gx\n iota = (0.0, 1.0)\n x0 = 10.0\n delta = 0.25\n Etrans = 0.008\n u = 4056.5\n\n k0 = sqrt(2 * u * Etrans - (1./(2 * delta * delta)))\n\n OPEN(UNIT = outunit, FILE = 'quiz1.txt', FORM = \"formatted\")\n x = 0.35 ! Starting point is 0.5 so in first iteration 0.35 + 0.15 = 0.5\n DO i = 1, 128 ! Grid points = 128\n x = x + 0.15 ! With dexX = 0.15 \n Gx = ((1. / (pi * delta * delta)) ** (1./4.)) * EXP(-((x - x0) * (x - x0)) / (2 * delta * delta)) * EXP(-iota * k0 * x) ! No need of iota term it will be 1 after squre\n !\n !\n !!!!!!! Disclaimer --> Do not exclude iota term even it will become 1 after computation --> My 3 marks gone for this single mistake\n !\n !\n WRITE(outunit, * ) x, abs(Gx*Gx)\n ENDDO\n CLOSE(outunit)\nEND\n", "meta": {"hexsha": "6b69e95e437dbcb0e7ccf4cba0ec2035d015815f", "size": 1037, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "3. Lab-2/q.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": "3. Lab-2/q.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": "3. Lab-2/q.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": 33.4516129032, "max_line_length": 175, "alphanum_fraction": 0.5072324012, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.8019611441187385}} {"text": "! { dg-do run }\n! { dg-options \"-ffloat-store\" }\n!\n! PR fortran/33197\n!\n! Check for Fortran 2008's ATAN(Y,X) - which is equivalent\n! to Fortran 77's ATAN2(Y,X).\n!\ninteger :: i\nreal, parameter :: pi4 = 2*acos(0.0)\nreal, parameter :: pi8 = 2*acos(0.0d0)\ndo i = 1, 10\n if(atan(1.0, i/10.0) -atan2(1.0, i/10.) /= 0.0) STOP 1\n if(atan(1.0d0,i/10.0d0)-atan2(1.0d0,i/10.0d0) /= 0.0d0) STOP 2\nend do\n\n! Atan(1,1) = Pi/4\nif (abs(atan(1.0,1.0) -pi4/4.0) > epsilon(pi4)) STOP 3\nif (abs(atan(1.0d0,1.0d0)-pi8/4.0d0) > epsilon(pi8)) STOP 4\n\n! Atan(-1,1) = -Pi/4\nif (abs(atan(-1.0,1.0) +pi4/4.0) > epsilon(pi4)) STOP 5\nif (abs(atan(-1.0d0,1.0d0)+pi8/4.0d0) > epsilon(pi8)) STOP 6\n\n! Atan(1,-1) = 3/4*Pi\nif (abs(atan(1.0,-1.0) -3.0*pi4/4.0) > epsilon(pi4)) STOP 7\nif (abs(atan(1.0d0,-1.0d0)-3.0d0*pi8/4.0d0) > epsilon(pi8)) STOP 8\n\n! Atan(-1,-1) = -3/4*Pi\nif (abs(atan(-1.0,-1.0) +3.0*pi4/4.0) > epsilon(pi4)) STOP 9\nif (abs(atan(-1.0d0,-1.0d0)+3.0d0*pi8/4.0d0) > epsilon(pi8)) STOP 10\n\n! Atan(3,-5) = 2.60117315331920908301906501867... = Pi - 3/2 atan(3/5)\nif (abs(atan(3.0,-5.0) -2.60117315331920908301906501867) > epsilon(pi4)) STOP 11\nif (abs(atan(3.0d0,-5.0d0)-2.60117315331920908301906501867d0) > epsilon(pi8)) STOP 12\n\nend\n", "meta": {"hexsha": "df9381b113792378d934b9e6cc23324ec0e12aec", "size": 1252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/atan2_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/atan2_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/atan2_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": 32.9473684211, "max_line_length": 85, "alphanum_fraction": 0.5998402556, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.8019611323304163}} {"text": "FUNCTION fbed(x,y) \nUSE types\nIMPLICIT NONE\nREAL(KIND=dp) :: x, y, fbed\nREAL(KIND=dp) :: Lxy, fsurf\n\nLxy = 100.0 \n\nfbed = 10.0*(COS(6.0*Pi*x/Lxy)*COS(6.0*Pi*y/Lxy) -1.0)\n\nEND FUNCTION fbed\n", "meta": {"hexsha": "388acdf29b58cb89236995b8c10d3de613a8ab45", "size": 192, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmark_apps/elmerfem/elmerice/Tests/Grounded/PROG/fbed.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/elmerice/Tests/Grounded/PROG/fbed.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/elmerice/Tests/Grounded/PROG/fbed.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": 16.0, "max_line_length": 54, "alphanum_fraction": 0.6302083333, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.959762060829178, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.8018653974277214}} {"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\n\n common /compi/ pi\n\n r = 1.d0 + alpha*cos(2.d0*pi*(yc + xc))\n\n xp = r*cos(2.d0*pi*xc)\n yp = r*sin(2.d0*pi*xc)\n zp = alpha*sin(2.d0*pi*(yc + xc))\n\n end\n", "meta": {"hexsha": "145af5fb44252f74e7142978ba28f153e198c151", "size": 390, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/torus/mapc2m_twisted_torus.f", "max_stars_repo_name": "MelodyShih/forestclaw", "max_stars_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "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": "src/mappings/torus/mapc2m_twisted_torus.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": "src/mappings/torus/mapc2m_twisted_torus.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": 20.5263157895, "max_line_length": 67, "alphanum_fraction": 0.5717948718, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254526, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.8018653955471468}} {"text": "program main\r\n!***********************************************************\r\n! program to solve a finite difference \r\n! discretization of Helmholtz equation : \r\n! (d2/dx2)u + (d2/dy2)u - alpha u = f \r\n! using Jacobi iterative method. \r\n!\r\n! Modified: Sanjiv Shah, Kuck and Associates, Inc. (KAI), 1998\r\n! Author: Joseph Robicheaux, Kuck and Associates, Inc. (KAI), 1998\r\n! \r\n! Directives are used in this code to achieve paralleism. \r\n! All do loops are parallized with default 'static' scheduling.\r\n! \r\n! Input : n - grid dimension in x direction \r\n! m - grid dimension in y direction\r\n! alpha - Helmholtz constant (always greater than 0.0)\r\n! tol - error tolerance for iterative solver\r\n! relax - Successice over relaxation parameter\r\n! mits - Maximum iterations for iterative solver\r\n!\r\n! On output \r\n! : u(n,m) - Dependent variable (solutions)\r\n! : f(n,m) - Right hand side function \r\n!************************************************************\r\n implicit none \r\n\r\n integer n,m,mits \r\n double precision tol,relax,alpha \r\n\r\n common /idat/ n,m,mits\r\n common /fdat/tol,alpha,relax\r\n! \r\n! Read info \r\n! \r\n write(*,*) \"Input n,m - grid dimension in x,y direction \" \r\n read(5,*) n,m \r\n write(*,*) \"Input alpha - Helmholts constant \" \r\n read(5,*) alpha\r\n write(*,*) \"Input relax - Successive over-relaxation parameter\"\r\n read(5,*) relax \r\n write(*,*) \"Input tol - error tolerance for iterative solver\" \r\n read(5,*) tol \r\n write(*,*) \"Input mits - Maximum iterations for solver\" \r\n read(5,*) mits\r\n\r\n!\r\n! Calls a driver routine \r\n! \r\n call driver () \r\n\r\n stop\r\nend program\r\n\r\nsubroutine driver ( ) \r\n!************************************************************\r\n! Subroutine driver () \r\n! This is where the arrays are allocated and initialzed. \r\n!\r\n! Working varaibles/arrays \r\n! dx - grid spacing in x direction \r\n! dy - grid spacing in y direction \r\n!************************************************************\r\n implicit none \r\n\r\n integer n,m,mits,mtemp \r\n double precision tol,relax,alpha \r\n\r\n common /idat/ n,m,mits,mtemp\r\n common /fdat/tol,alpha,relax\r\n\r\n double precision u(n,m),f(n,m),dx,dy\r\n\r\n! Initialize data\r\n\r\n call initialize (n,m,alpha,dx,dy,u,f)\r\n\r\n! Solve Helmholtz equation\r\n\r\n call jacobi (n,m,dx,dy,alpha,relax,u,f,tol,mits)\r\n\r\n! Check error between exact solution\r\n\r\n call error_check (n,m,alpha,dx,dy,u,f)\r\n\r\n return \r\nend subroutine driver\r\n\r\nsubroutine initialize (n,m,alpha,dx,dy,u,f) \r\n!*****************************************************\r\n! Initializes data \r\n! Assumes exact solution is u(x,y) = (1-x^2)*(1-y^2)\r\n!\r\n!*****************************************************\r\n implicit none \r\n \r\n integer n,m\r\n double precision u(n,m),f(n,m),dx,dy,alpha\r\n \r\n integer i,j, xx,yy\r\n double precision PI \r\n parameter (PI=3.1415926)\r\n\r\n dx = 2.0 / (n-1)\r\n dy = 2.0 / (m-1)\r\n\r\n! Initilize initial condition and RHS\r\n\r\n!$omp parallel do private(xx,yy)\r\n do j = 1,m\r\n do i = 1,n\r\n xx = -1.0 + dx * dble(i-1) ! -1 < x < 1\r\n yy = -1.0 + dy * dble(j-1) ! -1 < y < 1\r\n u(i,j) = 0.0 \r\n f(i,j) = -alpha *(1.0-xx*xx)*(1.0-yy*yy) &\r\n - 2.0*(1.0-xx*xx)-2.0*(1.0-yy*yy)\r\n enddo\r\n enddo\r\n!$omp end parallel do\r\n\r\n return \r\nend subroutine initialize\r\n\r\nsubroutine jacobi (n,m,dx,dy,alpha,omega,u,f,tol,maxit)\r\n!*****************************************************************\r\n! Subroutine HelmholtzJ\r\n! Solves poisson equation on rectangular grid assuming : \r\n! (1) Uniform discretization in each direction, and \r\n! (2) Dirichlect boundary conditions \r\n! \r\n! Jacobi method is used in this routine \r\n!\r\n! Input : n,m Number of grid points in the X/Y directions \r\n! dx,dy Grid spacing in the X/Y directions \r\n! alpha Helmholtz eqn. coefficient \r\n! omega Relaxation factor \r\n! f(n,m) Right hand side function \r\n! u(n,m) Dependent variable/Solution\r\n! tol Tolerance for iterative solver \r\n! maxit Maximum number of iterations \r\n!\r\n! Output : u(n,m) - Solution \r\n!****************************************************************\r\n implicit none \r\n integer n,m,maxit\r\n double precision dx,dy,f(n,m),u(n,m),alpha, tol,omega\r\n!\r\n! Local variables \r\n! \r\n integer i,j,k,k_local \r\n double precision error,resid,rsum,ax,ay,b\r\n double precision error_local, uold(n,m)\r\n\r\n real ta,tb,tc,td,te,ta1,ta2,tb1,tb2,tc1,tc2,td1,td2\r\n real te1,te2\r\n real second\r\n external second\r\n!\r\n! Initialize coefficients \r\n ax = 1.0/(dx*dx) ! X-direction coef \r\n ay = 1.0/(dy*dy) ! Y-direction coef\r\n b = -2.0/(dx*dx)-2.0/(dy*dy) - alpha ! Central coeff \r\n\r\n error = 10.0 * tol \r\n k = 1\r\n\r\n do while (k.le.maxit .and. error.gt. tol) \r\n\r\n error = 0.0 \r\n\r\n! Copy new solution into old\r\n!$omp parallel\r\n\r\n!$omp do \r\n do j=1,m\r\n do i=1,n\r\n uold(i,j) = u(i,j) \r\n enddo\r\n enddo\r\n\r\n! Compute stencil, residual, & update\r\n\r\n!$omp do private(resid) reduction(+:error)\r\n do j = 2,m-1\r\n do i = 2,n-1 \r\n! Evaluate residual \r\n resid = (ax*(uold(i-1,j) + uold(i+1,j)) &\r\n + ay*(uold(i,j-1) + uold(i,j+1)) &\r\n + b * uold(i,j) - f(i,j))/b\r\n! Update solution \r\n u(i,j) = uold(i,j) - omega * resid\r\n! Accumulate residual error\r\n error = error + resid*resid \r\n end do\r\n enddo\r\n!$omp enddo nowait\r\n\r\n!$omp end parallel\r\n\r\n! Error check \r\n\r\n k = k + 1\r\n\r\n error = sqrt(error)/dble(n*m)\r\n!\r\n enddo ! End iteration loop \r\n!\r\n print *, 'Total Number of Iterations ', k \r\n print *, 'Residual ', error \r\n\r\n return \r\nend subroutine jacobi\r\n\r\nsubroutine error_check (n,m,alpha,dx,dy,u,f) \r\n implicit none \r\n!***********************************************************\r\n! Checks error between numerical and exact solution \r\n!\r\n!*********************************************************** \r\n \r\n integer n,m\r\n double precision u(n,m),f(n,m),dx,dy,alpha \r\n \r\n integer i,j\r\n double precision xx,yy,temp,error \r\n\r\n dx = 2.0 / (n-1)\r\n dy = 2.0 / (m-1)\r\n error = 0.0 \r\n\r\n!$omp parallel do private(xx,yy,temp) reduction(+:error)\r\n do j = 1,m\r\n do i = 1,n\r\n xx = -1.0d0 + dx * dble(i-1)\r\n yy = -1.0d0 + dy * dble(j-1)\r\n temp = u(i,j) - (1.0-xx*xx)*(1.0-yy*yy)\r\n error = error + temp*temp \r\n enddo\r\n enddo\r\n \r\n error = sqrt(error)/dble(n*m)\r\n\r\n print *, 'Solution Error : ',error\r\n\r\n return \r\nend subroutine error_check\r\n\r\n", "meta": {"hexsha": "4abfe882fef67a778a18aea66cd8b5f5185f5327", "size": 6973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/D-TEC/jacobi.f90", "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/D-TEC/jacobi.f90", "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/D-TEC/jacobi.f90", "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": 28.2307692308, "max_line_length": 70, "alphanum_fraction": 0.498063961, "num_tokens": 1893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.8018182511385779}} {"text": "! Harmonic Series\r\n\r\n! How We Got From There To Here:\r\n! A Story of Real Analysis\r\n! page 130 - 132\r\n! https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant\r\n\r\n \r\n program EMConst\r\nC implicit none\r\nC https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html\r\nC https://stackoverflow.com/questions/10884260/how-can-gfortran-tell-if-i-am-compiling-f90-or-f95-code\r\n use ISO_FORTRAN_ENV \r\nC https://stackoverflow.com/questions/3170239/fortran-integer4-vs-integer4-vs-integerkind-4#3170438\r\n integer(kind=int32) :: n\r\n integer, parameter :: rp = selected_real_kind(15)\r\n integer (kind = int32) :: i\r\n Real (kind = rp) :: b\r\n Real (kind = rp) :: a\r\n n = huge(n) ! https://stackoverflow.com/questions/9569756/fortran-the-largest-and-the-smallest-integer\r\n a = 0.0_rp\r\n do i = 1,(n-1),1\r\n a = (a + (1.0_rp/i)) \r\n end do\r\n b = log(real(n)) !https://gcc.gnu.org/onlinedocs/gfortran/REAL.html\r\n print *, a - b\r\n end program EMConst\r\n\r\n\r\nC gfortran EMConst.f -o EMConst.out\r\nC ./EMConst.out\r\n\r\n", "meta": {"hexsha": "8b8aa09292b0f9dd5a56ee5ef4585bc85e269163", "size": 1152, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EMConst.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": "EMConst.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": "EMConst.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": 34.9090909091, "max_line_length": 112, "alphanum_fraction": 0.6102430556, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.8018182489446832}} {"text": "! This version avoids catastrophic cancellation in computing in \n! adding or subtracting -b and sqrt(b**2 - 4*a*c).\n!\n! It also reorders x1true and x2true if necessary so x1true <= x2true.\n\nprogram quadratic\n\n implicit none\n real(kind=8) :: a,b,c,x1,x2,x1true, x2true, err1, err2, s, xtemp\n print *, \"input x1true, x2true: \"\n read *, x1true, x2true\n\n if (x1true > x2true) then\n xtemp = x1true\n x1true = x2true\n x2true = xtemp\n print *, \"Re-ordered x1true and x2true\"\n endif\n\n a = 1.d0\n b = -(x1true + x2true)\n c = x1true*x2true\n\n\tprint 600, a,b,c\n600 format(/,\"Coefficients: a = \",e16.6, \" b = \",e16.6, \" c = \",e16.6,/)\n\n s = sqrt(b**2 - 4.d0*a*c)\n\n if (b>0.d0) then\n x1 = (-b - s) / (2.d0*a)\n x2 = c / x1\n else\n x2 = (-b + s) / (2.d0*a)\n x1 = c / x2\n endif\n\n err1 = x1 - x1true\n err2 = x2 - x2true\n\n print 601, 1, x1, x1true\n print 602, abs(err1), abs(err1/x1true)\n print *, ' '\n print 601, 2, x2, x2true\n print 602, abs(err2), abs(err2/x2true)\n\n601 format(\"Root x\",i1,\" computed: \",e22.15,\" true: \",e22.15)\n602 format(\" absolute error: \",e16.6,\" relative error: \",e16.6)\n\n\nend program quadratic\n", "meta": {"hexsha": "9719988355ec0db2ea66014d928afc2308628792", "size": 1231, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab9/quadratic2.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/labs/lab9/quadratic2.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/labs/lab9/quadratic2.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": 24.137254902, "max_line_length": 75, "alphanum_fraction": 0.5580828595, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8902942188450159, "lm_q1q2_score": 0.8017364648552011}} {"text": "\tFUNCTION PR_WCHT ( tmpf, sknt )\nC************************************************************************\nC* PR_WCHT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes WCHT, the wind chill temperature from TMPF\t*\nC* and SKNT. The input values will first be converted to miles per\t*\nC* hour. The output will be calculated in Fahrenheit.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WCHT 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_WCHT = 35.74 + ( .6215 * TMPF ) - 35.75 * WCI ( V ) +\t*\nC*\t\t 0.4274 * TMPF * WCI ( V )\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\t\twhere: \tWCI ( V ) = ( V ** 0.16 )\t\t\t*\nC*\t\t\tV: Wind Speed (mph)\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_WCHT ( 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_WCHT\t\tREAL\t\tWind Chill temperature in deg F\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* T. Lee/SAIC\t\t 9/01\t\t\t\t\t\t*\nC* T. Lee/SAIC\t\t 9/01\tSet windchill <= air temp\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'ERMISS.FNC'\nC*\n\tWCI ( vel ) = ( vel ** 0.16 )\nC------------------------------------------------------------------------\nC*\tConvert input variables to mph.\nC\n\tsmph = PR_KNMH ( sknt )\nC\nC*\tCompute the wind chill temp if the inputs are not missing\nC*\tand the wind speed is greater than 3 mph.\nC\n\tIF ( ( ERMISS ( tmpf ) ) .or. ( ERMISS ( smph ) ) ) THEN\n\t PR_WCHT = RMISSD\n\tELSE IF ( smph .le. 3. ) THEN\n\t PR_WCHT = tmpf\n\tELSE\n\t wcht = 35.74 + .6215 * tmpf - 35.75 * WCI ( smph ) +\n +\t\t .4275 * tmpf * WCI ( smph )\n\t IF ( wcht .gt. tmpf ) THEN\n\t\tPR_WCHT = tmpf\n\t ELSE\n\t\tPR_WCHT = wcht\n\t END IF\n\tEND IF\nC\n\tRETURN\n\tEND\n", "meta": {"hexsha": "0ce97aebde285fdd268c7a4b3fdbfefdefdf2603", "size": 1879, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prwcht.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/prwcht.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/prwcht.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.8032786885, "max_line_length": 73, "alphanum_fraction": 0.499733901, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.8016498630921571}} {"text": "program findroot\n\n implicit none\n\n print *, \"x0 = \", root(F, 1.5, 2.5, 1e-12)\n \n contains\n\n function F(x)\n real, intent(in) :: x\n real F\n F = (x - 2)*(x + 1)\n end function\n\n function root(func, a, b, eps)\n interface\n function func(x) result(y)\n real, intent(in) :: x\n real :: y\n end function func\n end interface\n real, intent(in) :: a, b, eps\n real :: root\n \n real :: l, r, m\n real :: lv, rv, mv\n\n l = a; r = b\n lv = func(l); rv = func(r)\n \n if (lv*rv > 0) stop -1 ! invalid input\n \n do while (l - r > eps)\n m = (l + r)/2\n mv = func(m)\n if (mv*lv > 0) then\n l = m\n else if (mv*rv > 0) then\n r = m\n else\n exit ! now we must have mv == 0\n end if\n end do\n\n root = (l + r)/2\n end function root\n\nend program findroot\n\n", "meta": {"hexsha": "9cfe9b72f0c8e88c620b8b3f4e62da526a4b508b", "size": 1050, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "findroot.f90", "max_stars_repo_name": "CXuesong/LearnFortran", "max_stars_repo_head_hexsha": "1bf355ba83f4da48b921a9a54c61bcc178422266", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "findroot.f90", "max_issues_repo_name": "CXuesong/LearnFortran", "max_issues_repo_head_hexsha": "1bf355ba83f4da48b921a9a54c61bcc178422266", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "findroot.f90", "max_forks_repo_name": "CXuesong/LearnFortran", "max_forks_repo_head_hexsha": "1bf355ba83f4da48b921a9a54c61bcc178422266", "max_forks_repo_licenses": ["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.0, "max_line_length": 69, "alphanum_fraction": 0.3857142857, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.8016253426966672}} {"text": "module routines\n\n use healpix_types\n\n implicit none\n\n contains\n\n subroutine QuadraticEquationSolver(a, b, c, root1, root2)\n\n implicit none\n real(kind=dp), intent(in) :: a, b, c\n real(kind=dp), intent(out) :: root1, root2\n\n real(kind=dp) :: d\n\n d = b * b - 4.0_dp * a * c\n\n if ( d >= 0.0_dp ) then\n\n d = dsqrt(d)\n\n root1 = (-b + d) / (2.0_dp * a)\n root2 = (-b - d) / (2.0_dp * a)\n\n else\n\n write(*, *) \"ERROR: There is no real roots!\"\n write(*, *) \"Discriminant = \", d\n\n end if\n\n end subroutine QuadraticEquationSolver\n\n\nend module routines\n", "meta": {"hexsha": "24691543ab29827ab5c30eedc715ce6e41afcaa7", "size": 623, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/routines.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/routines.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/routines.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": 16.8378378378, "max_line_length": 61, "alphanum_fraction": 0.532905297, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8016253310967618}} {"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\nend module funcs\n", "meta": {"hexsha": "8085a59f025a1c419523e49777d41f2ea6206ac2", "size": 239, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ME_Numerical_Methods/HW4/ex1/c-d/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/c-d/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/c-d/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": 13.2777777778, "max_line_length": 30, "alphanum_fraction": 0.6569037657, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8015084675409021}} {"text": "c\t=========================\nc\tMAIN PROGRAM\nc\t\t4th order Runge Kutta\nc\t=========================\n program main\n real*8 f, g\n real*8 t, p, th, dt, E, E0, error\n real*8 k1, k2, k3, k4, l1, l2, l3, l4\nc\t\tThe dimension of the following tables must be equal to the number of iterations N\n real*8 ts(1000), ps(1000), ths(1000), Es(1000)\n integer N, i, j\n i = 1\n\nc\tParameters\n N = 1000\n\nc\tInitial values\n E0 = 15.0d-1\n h = 1.0d0\n10 continue\n t = 0.0d0\n th = 0.0d0\n p = sqrt(2.0d0+2.0d0*E0)\n\nc\tRK4 coefficients\n20 continue\n k1 = h*f(t, th, p)\n l1 = h*g(t, th, p)\n k2 = h*f(t+5.0d-1*h, th+5.0d-1*k1, p+5.0d-1*l1)\n l2 = h*g(t+5.0d-1*h, th+5.0d-1*k1, p+5.0d-1*l1)\n k3 = h*f(t+5.0d-1*h, th+5.0d-1*k2, p+5.0d-1*l2)\n l3 = h*g(t+5.0d-1*h, th+5.0d-1*k2, p+5.0d-1*l2)\n k4 = h*f(t+h, th+k1, p+l1)\n l4 = h*g(t+h, th+k1, p+l1)\n\nc\tNext value of variables\n t = t + h\n ts(i) = t\n th = th + h*(k1 + 2.0d0*k2 + 2.0d0*k3 + k4)/6.0d0\n ths(i) = th\n p = p + h*(l1 + 2.0d0*l2 + 2.0d0*l3 + l4)/6.0d0\n ps(i) = p\n\nc\tEnergy and error in Energy\n E = p**2/2.0d0 - dcos(th)\n Es = E\n error = abs((E-E0)/E0)\n\nc\tChecking for adequacy in the error\n if (error.gt.1.0d-6) then\n h = h/2.0d0\n i = 1\n go to 10\n endif\n\nc\tContinuing with the N iterations\n i = i + 1\n if (i.le.N) then\n go to 20\n endif\n\nc\tExport of values for t, p, th, E\n open(unit=51, file='dataT.txt')\n do j=1,N\n write(51,*) ts(j)\n enddo\n close(51)\n\n open(unit=52, file='dataP.txt')\n do j=1,N\n write(52,*) ps(j)\n enddo\n close(52)\n\n open(unit=53, file='dataTH.txt')\n do j=1,N\n write(53,*) ths(j)\n enddo\n close(53)\n\n open(unit=54, file='dataE.txt')\n do j=1,N\n write(54,*) Es(j)\n enddo\n close(54)\n\nc\tEnd of main program\n end\n\n\n\nc\t==========\nc\tFUNCTION\nc\t\tq' = p\nc\t==========\n real*8 function f(t,th,p)\n real*8 p, th, t \n \n f = p\n \n return\n end\n\nc\t=================\nc\tFUNCTION\nc\t\tp' = -sin(th)\nc\t=================\n real*8 function g(t,th,p)\n real*8 th,p,t\n \n g = -dsin(th)\n \n return\n end\n\n", "meta": {"hexsha": "01122834b1e3136f883775ac48ee62a9f3cf1709", "size": 2308, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "computational math/numerical integral calculation - differential equation integration 2(a1).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 2(a1).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 2(a1).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": 19.8965517241, "max_line_length": 84, "alphanum_fraction": 0.4584055459, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8652240895276223, "lm_q1q2_score": 0.8014602981490978}} {"text": "module mesh\n\nuse types, only: dp\nuse utils, only: stop_error\n\nimplicit none\n\nprivate\npublic meshexp, meshexp_der, get_meshexp_pars, meshexp_der2, &\n linspace, meshgrid\n\ncontains\n\nfunction meshexp(rmin, rmax, a, N) result(mesh)\n! Generates exponential mesh of N elements on [rmin, rmax]\n!\n! Arguments\n! ---------\n!\n! The domain [rmin, rmax], the mesh will contain both endpoints:\nreal(dp), intent(in) :: rmin, rmax\n!\n! The ratio of the rightmost to leftmost element lengths in the mesh (for a > 1\n! this means the \"largest/smallest\"); The only requirement is a > 0. For a == 1\n! a uniform mesh will be returned:\nreal(dp), intent(in) :: a\n!\n! The number of elements in the mesh:\ninteger, intent(in) :: N\n!\n! Returns\n! -------\n!\n! The generated mesh:\nreal(dp) :: mesh(N+1)\n!\n! Note: Every exponential mesh is fully determined by the set of parameters\n! (rmin, rmax, a, N). Use the get_meshexp_pars() subroutine to obtain them\n! from the given mesh.\n!\n! Example\n! -------\n!\n! real(dp) :: r(11)\n! r = meshexp(0._dp, 50._dp, 1e9_dp, 10)\n\ninteger :: i\nreal(dp) :: alpha, beta\nif (a < 0) then\n call stop_error(\"meshexp: a > 0 required\")\nelse if (abs(a - 1) < tiny(1._dp)) then\n alpha = (rmax - rmin) / N\n do i = 1, N+1\n mesh(i) = alpha * (i-1.0_dp) + rmin\n end do\nelse\n if (N > 1) then\n beta = log(a) / (N-1)\n alpha = (rmax - rmin) / (exp(beta*N) - 1)\n do i = 1, N+1\n mesh(i) = alpha * (exp(beta*(i-1)) - 1) + rmin\n end do\n else if (N == 1) then\n mesh(1) = rmin\n mesh(2) = rmax\n else\n call stop_error(\"meshexp: N >= 1 required\")\n end if\nend if\nend function\n\nfunction meshexp_der(rmin, rmax, a, N) result(Rp)\n! Generates dR/dt where R(t) is the mesh returned by meshexp()\n!\n! Input parameters the same as for meshexp(). The variable \"t\" is defined by:\n! t = 1, 2, ..., N+1\n! So it describes a uniform mesh, with a step size 1, and the corresponding\n! physical points are given by the R(t) array.\n!\n! Output parameters:\n! Rp(N+1) ....... dR/dt\nreal(dp), intent(in) :: rmin\nreal(dp), intent(in) :: rmax\nreal(dp), intent(in) :: a\ninteger, intent(in) :: N\nreal(dp) :: Rp(N+1)\n\ninteger :: i\nreal(dp) :: alpha, beta\nif (a < 0) then\n call stop_error(\"meshexp_der: a > 0 required\")\nelse if (abs(a - 1) < tiny(1._dp)) then\n call stop_error(\"meshexp_der: a == 1 not implemented\")\nelse\n if (N > 1) then\n beta = log(a)/(N-1)\n alpha = (rmax - rmin) / (exp(beta*N) - 1)\n do i = 1, N+1\n Rp(i) = alpha * beta * exp(beta*(i-1))\n end do\n else\n call stop_error(\"meshexp_der: N > 1 required\")\n end if\nend if\nend function\n\nfunction meshexp_der2(rmin, rmax, a, N) result(Rpp)\n! Generates d^R/dt^2 where R(t) is the mesh returned by meshexp()\n!\n! Input parameters the same as for meshexp(). The variable \"t\" is defined by:\n! t = 1, 2, ..., N+1\n! So it describes a uniform mesh, with a step size 1, and the corresponding\n! physical points are given by the R(t) array.\n!\n! Output parameters:\n! Rp(N+1) ....... d^2R/dt^2\nreal(dp), intent(in) :: rmin\nreal(dp), intent(in) :: rmax\nreal(dp), intent(in) :: a\ninteger, intent(in) :: N\nreal(dp) :: Rpp(N+1)\n\ninteger :: i\nreal(dp) :: alpha, beta\nif (a < 0) then\n call stop_error(\"meshexp_der2: a > 0 required\")\nelse if (abs(a - 1) < tiny(1._dp)) then\n call stop_error(\"meshexp_der2: a == 1 not implemented\")\nelse\n if (N > 1) then\n beta = log(a)/(N-1)\n alpha = (rmax - rmin) / (exp(beta*N) - 1)\n do i = 1, N+1\n Rpp(i) = alpha * beta**2 * exp(beta*(i-1))\n end do\n else\n call stop_error(\"meshexp_der2: N > 1 required\")\n end if\nend if\nend function\n\nsubroutine get_meshexp_pars(R, rmin, rmax, a, N)\n! Given any exponential mesh R, it determines the get_mesh()'s parameters\n!\n! This only looks at the number of elements, the leftmost and the rightmost\n! elements (so the middle elements are not checked/taken into account).\nreal(dp), intent(in) :: R(:)\nreal(dp), intent(out) :: rmin, rmax, a\ninteger, intent(out) :: N\nrmin = R(1)\nrmax = R(size(R))\na = (R(size(R)) - R(size(R)-1)) / (R(2) - R(1))\nN = size(R) - 1\nend subroutine\n\nfunction linspace(a, b, n) result(s)\nreal(dp), intent(in) :: a, b\ninteger, intent(in) :: n\nreal(dp) :: s(n)\ns = meshexp(a, b, 1.0_dp, n-1)\nend function\n\nsubroutine meshgrid(x, y, x2, y2)\nreal(dp), intent(in) :: x(:), y(:)\nreal(dp), intent(out) :: x2(:, :), y2(:, :)\nx2 = spread(x, 1, size(y))\ny2 = spread(y, 2, size(x))\nend subroutine\n\nend module\n", "meta": {"hexsha": "fcc4cb899aed590d17b707deb812dd8c2ff90780", "size": 4501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesh.f90", "max_stars_repo_name": "certik/hfsolver", "max_stars_repo_head_hexsha": "b4c50c1979fb7e468b1852b144ba756f5a51788d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2015-03-24T13:06:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T00:14:02.000Z", "max_issues_repo_path": "src/mesh.f90", "max_issues_repo_name": "certik/hfsolver", "max_issues_repo_head_hexsha": "b4c50c1979fb7e468b1852b144ba756f5a51788d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-03-25T04:59:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-06-06T23:00:09.000Z", "max_forks_repo_path": "src/mesh.f90", "max_forks_repo_name": "certik/hfsolver", "max_forks_repo_head_hexsha": "b4c50c1979fb7e468b1852b144ba756f5a51788d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-24T15:35:43.000Z", "avg_line_length": 26.3216374269, "max_line_length": 79, "alphanum_fraction": 0.6100866474, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250325, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.8014602933203372}} {"text": " subroutine orth_random ( n, seed, a )\n\nc*********************************************************************72\nc\ncc ORTH_RANDOM returns the ORTH_RANDOM matrix.\nc\nc Discussion:\nc\nc The matrix is a random orthogonal matrix.\nc\nc Properties:\nc\nc The inverse of A is equal to A'.\nc A is orthogonal: A * A' = A' * A = I.\nc Because A is orthogonal, it is normal: A' * A = A * A'.\nc Columns and rows of A have unit Euclidean norm.\nc Distinct pairs of columns of A are orthogonal.\nc Distinct pairs of rows of A are orthogonal.\nc The L2 vector norm of A*x = the L2 vector norm of x for any vector x.\nc The L2 matrix norm of A*B = the L2 matrix norm of B for any matrix B.\nc det ( A ) = +1 or -1.\nc A is unimodular.\nc All the eigenvalues of A have modulus 1.\nc All singular values of A are 1.\nc All entries of A are between -1 and 1.\nc\nc Discussion:\nc\nc Thanks to Eugene Petrov, B I Stepanov Institute of Physics,\nc National Academy of Sciences of Belarus, for convincingly\nc pointing out the severe deficiencies of an earlier version of\nc this routine.\nc\nc Essentially, the computation involves saving the Q factor of the\nc QR factorization of a matrix whose entries are normally distributed.\nc However, it is only necessary to generate this matrix a column at\nc a time, since it can be shown that when it comes time to annihilate\nc the subdiagonal elements of column K, these (transformed) elements of\nc column K are still normally distributed random values. Hence, there\nc is no need to generate them at the beginning of the process and\nc transform them K-1 times.\nc\nc For computational efficiency, the individual Householder transformations\nc could be saved, as recommended in the reference, instead of being\nc accumulated into an explicit matrix format.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license.\nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Reference:\nc\nc Pete Stewart,\nc Efficient Generation of Random Orthogonal Matrices With an Application\nc to Condition Estimators,\nc SIAM Journal on Numerical Analysis,\nc Volume 17, Number 3, June 1980, pages 403-409.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc\nc Input/output, integer SEED, a seed for the random number\nc generator.\nc\nc Output, double precision A(N,N), the matrix.\nc\n implicit none\n\n integer n\n\n double precision a(n,n)\n integer i\n integer j\n double precision r8_normal_01\n integer seed\n double precision v(n)\n double precision x(n)\nc\nc Start with A = the identity matrix.\nc\n do i = 1, n\n do j = 1, n\n if ( i .eq. j ) then\n a(i,j) = 1.0D+00\n else\n a(i,j) = 0.0D+00\n end if\n end do\n end do\nc\nc Now behave as though we were computing the QR factorization of\nc some other random matrix. Generate the N elements of the first column,\nc compute the Householder matrix H1 that annihilates the subdiagonal elements,\nc and set A := A * H1' = A * H.\nc\nc On the second step, generate the lower N-1 elements of the second column,\nc compute the Householder matrix H2 that annihilates them,\nc and set A := A * H2' = A * H2 = H1 * H2.\nc\nc On the N-1 step, generate the lower 2 elements of column N-1,\nc compute the Householder matrix HN-1 that annihilates them, and\nc and set A := A * H(N-1)' = A * H(N-1) = H1 * H2 * ... * H(N-1).\nc This is our random orthogonal matrix.\nc\n do j = 1, n - 1\nc\nc Set the vector that represents the J-th column to be annihilated.\nc\n do i = 1, j - 1\n x(i) = 0.0D+00\n end do\n\n do i = j, n\n x(i) = r8_normal_01 ( seed )\n end do\nc\nc Compute the vector V that defines a Householder transformation matrix\nc H(V) that annihilates the subdiagonal elements of X.\nc\n call r8vec_house_column ( n, x, j, v )\nc\nc Postmultiply the matrix A by H'(V) = H(V).\nc\n call r8mat_house_axh ( n, a, v, a )\n\n end do\n\n return\n end\n subroutine pds_random ( n, seed, a )\n\nc*********************************************************************72\nc\ncc PDS_RANDOM returns the PDS_RANDOM matrix.\nc\nc Discussion:\nc\nc The matrix is a \"random\" positive definite symmetric matrix.\nc\nc The matrix returned will have eigenvalues in the range [0,1].\nc\nc Properties:\nc\nc A is symmetric: A' = A.\nc\nc A is positive definite: 0 .lt. x'*A*x for nonzero x.\nc\nc The eigenvalues of A will be real.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license.\nc\nc Modified:\nc\nc BY Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc\nc Input/output, integer SEED, a seed for the random \nc number generator.\nc\nc Output, double precision A(N,N), the matrix.\nc\n implicit none\n\n integer n\n\n double precision a(n,n)\n integer i\n integer j\n integer k\n double precision lambda(n)\n double precision q(n,n)\n integer seed\nc\nc Get a random set of eigenvalues.\nc\n call r8vec_uniform_01 ( n, seed, lambda )\nc\nc Get a random orthogonal matrix Q.\nc\n call orth_random ( n, seed, q )\nc\nc Set A = Q * Lambda * Q'.\nc\n do i = 1, n\n do j = 1, n\n a(i,j) = 0.0D+00\n do k = 1, n\n a(i,j) = a(i,j) + q(i,k) * lambda(k) * q(j,k)\n end do\n end do\n end do\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 Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\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 1\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 By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\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 1\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\nc\nc Although SEED can be represented exactly as a 32 bit integer,\nc it generally cannot be represented exactly as a 32 bit real number!\nc\n r8_uniform_01 = dble ( seed ) * 4.656612875D-10\n\n return\n end\n subroutine r83_cg ( n, a, b, x )\n\nc*********************************************************************72\nc\ncc R83_CG uses the conjugate gradient method on an R83 system.\nc\nc Discussion:\nc\nc The R83 storage format is used for a tridiagonal matrix.\nc The superdiagonal is stored in entries (1,2:N), the diagonal in\nc entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the\nc original matrix is \"collapsed\" vertically into the array.\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Example:\nc\nc Here is how an R83 matrix of order 5 would be stored:\nc\nc * A12 A23 A34 A45\nc A11 A22 A33 A44 A55\nc A21 A32 A43 A54 *\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, double precision A(3,N), the matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer n\n\n double precision a(3,n)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r83_mv ( n, n, a, x, ap )\n\n do i = 1, n\n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r83_mv ( n, n, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r83_dif2 ( m, n, a )\n\nc*********************************************************************72\nc\ncc R83_DIF2 returns the DIF2 matrix in R83 format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the order of the matrix.\nc\nc Output, double precision A(3,N), the matrix.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3,n)\n integer i\n integer j\n integer mn\n\n do j = 1, n\n do i = 1, 3\n a(i,j) = 0.0D+00\n end do\n end do\n\n mn = min ( m, n )\n\n do j = 1, mn\n a(2,j) = +2.0D+00\n end do\n\n do j = 2, mn\n a(1,j) = -1.0D+00\n end do\n\n if ( m .le. n ) then\n do j = 1, mn - 1\n a(3,j) = -1.0D+00\n end do\n else if ( n .lt. m ) then\n do j = 1, mn\n a(3,j) = -1.0D+00\n end do\n end if\n \n return\n end\n subroutine r83_mv ( m, n, a, x, b )\n\nc*********************************************************************72\nc\ncc R83_MV multiplies an R83 matrix times an R8VEC.\nc\nc Discussion:\nc\nc The R83 storage format is used for a tridiagonal matrix.\nc The superdiagonal is stored in entries (1,2:N), the diagonal in\nc entries (2,1:N), and the subdiagonal in (3,1:N-1). Thus, the\nc original matrix is \"collapsed\" vertically into the array.\nc\nc Example:\nc\nc Here is how an R83 matrix of order 5 would be stored:\nc\nc * A12 A23 A34 A45\nc A11 A22 A33 A44 A55\nc A21 A32 A43 A54 *\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, double precision A(3,N), the R83 matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(M), the product A * x.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3,n)\n double precision b(m)\n integer i\n integer j\n integer mn\n double precision x(n)\n\n do i = 1, m\n b(i) = 0.0D+00\n end do\n\n mn = min ( m, n )\n\n if ( n .eq. 1 ) then\n b(1) = a(2,1) * x(1)\n if ( 1 .lt. m ) then\n b(2) = a(3,1) * x(1)\n end if\n return\n end if\n\n b(1) = a(2,1) * x(1) \n & + a(1,2) * x(2)\n\n do j = 2, mn - 1\n b(j) = a(3,j-1) * x(j-1) \n & + a(2,j) * x(j) \n & + a(1,j+1) * x(j+1)\n end do\n\n b(mn) = a(3,mn-1) * x(mn-1) \n & + a(2,mn) * x(mn)\n\n if ( n .lt. m ) then\n b(mn+1) = b(mn+1) + a(3,mn) * x(mn)\n end if\n\n if ( m .lt. n ) then\n b(mn) = b(mn) + a(1,mn+1) * x(mn+1)\n end if\n\n return\n end\n subroutine r83_resid ( m, n, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R83_RESID computes the residual R = B-A*X for R83 matrices.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, double precision A(3,N), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3,n)\n double precision b(m)\n integer i\n double precision r(m)\n double precision x(n)\n\n call r83_mv ( m, n, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r83s_cg ( n, a, b, x )\n\nc*********************************************************************72\nc\ncc R83S_CG uses the conjugate gradient method on an R83S system.\nc\nc Discussion:\nc\nc The R83S storage format is used for a tridiagonal scalar matrix.\nc The vector A(3) contains the subdiagonal, diagonal, and superdiagonal\nc values that occur on every row.\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Example:\nc\nc Here is how an R83S matrix of order 5, stored as (A1,A2,A3), would\nc be interpreted:\nc\nc A2 A3 0 0 0\nc A1 A2 A3 0 0\nc 0 A1 A2 A3 0 \nc 0 0 A1 A2 A3\nc 0 0 0 A1 A2\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 09 July 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, double precision A(3), the matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer n\n\n double precision a(3)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r83s_mv ( n, n, a, x, ap )\n\n do i = 1, n\n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r83s_mv ( n, n, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r83s_dif2 ( m, n, a )\n\nc*********************************************************************72\nc\ncc R83S_DIF2 returns the DIF2 matrix in R83S format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc A is tridiagonal.\nc Because A is tridiagonal, it has property A (bipartite).\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc A is Toeplitz: constant along diagonals.\nc A is symmetric: A' = A.\nc Because A is symmetric, it is normal.\nc Because A is normal, it is diagonalizable.\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc A is positive definite.\nc A is an M matrix.\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc A has an LU factorization A = L * U, without pivoting.\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc L(I+1,I) = -I/(I+1)\nc The matrix U is upper bidiagonal, with diagonal elements\nc U(I,I) = (I+1)/I\nc and superdiagonal elements which are all -1.\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc The eigenvalues are\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc The corresponding eigenvector X(I) has entries\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc Simple linear systems:\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc det ( A ) = N + 1.\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 09 July 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the order of the matrix.\nc\nc Output, double precision A(3), the matrix.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3)\n\n a(1) = -1.0D+00\n a(2) = +2.0D+00\n a(3) = -1.0D+00\n\n return\n end\n subroutine r83s_mv ( m, n, a, x, b )\n\nc*********************************************************************72\nc\ncc R83S_MV multiplies an R83S matrix times an R8VEC.\nc\nc Discussion:\nc\nc The R83S storage format is used for a tridiagonal scalar matrix.\nc The vector A(3) contains the subdiagonal, diagonal, and superdiagonal\nc values that occur on every row.\nc\nc Example:\nc\nc Here is how an R83S matrix of order 5, stored as (A1,A2,A3), would\nc be interpreted:\nc\nc A2 A3 0 0 0\nc A1 A2 A3 0 0\nc 0 A1 A2 A3 0 \nc 0 0 A1 A2 A3\nc 0 0 0 A1 A2\nc\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 09 July 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, double precision A(3), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(M), the product A * x.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3)\n double precision b(m)\n integer i\n double precision x(n)\n\n do i = 1, m\n b(i) = 0.0D+00\n end do\n\n do i = 2, n\n b(i) = b(i) + a(1) * x(i-1)\n end do\n\n do i = 1, n\n b(i) = b(i) + a(2) * x(i)\n end do\n\n do i = 1, n - 1\n b(i) = b(i) + a(3) * x(i+1)\n end do\n\n return\n end\n subroutine r83s_resid ( m, n, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R83S_RESID computes the residual R = B-A*X for R83S matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 09 July 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, double precision A(3), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(3)\n double precision b(m)\n integer i\n double precision r(m)\n double precision x(n)\n\n call r83s_mv ( m, n, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r83t_cg ( n, a, b, x )\n\nc*********************************************************************72\nc\ncc R83T_CG uses the conjugate gradient method on an R83T system.\nc\nc Discussion:\nc\nc The R83T storage format is used for a tridiagonal matrix.\nc The superdiagonal is stored in entries (1:N-1,3), the diagonal in\nc entries (1:N,2), and the subdiagonal in (2:N,1). Thus, the\nc original matrix is \"collapsed\" horizontally into the array.\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 18 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, double precision A(N,3), the matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer n\n\n double precision a(n,3)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r83t_mv ( n, n, a, x, ap )\n\n do i = 1, n\n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r83t_mv ( n, n, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r83t_dif2 ( m, n, a )\n\nc*********************************************************************72\nc\ncc R83T_DIF2 returns the DIF2 matrix in R83T format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 18 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the order of the matrix.\nc\nc Output, double precision A(M,3), the matrix.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,3)\n integer i\n integer j\n integer mn\n\n do j = 1, 3\n do i = 1, m\n a(i,j) = 0.0D+00\n end do\n end do\n\n mn = min ( m, n )\n\n do i = 2, mn\n a(i,1) = -1.0D+00\n end do\n\n do i = 1, mn\n a(i,2) = +2.0D+00\n end do\n\n do i = 1, mn - 1\n a(i,3) = -1.0D+00\n end do\n\n if ( m .lt. n ) then\n a(mn,3) = -1.0D+00\n else if ( n .lt. m ) then\n a(mn+1,1) = -1.0D+00\n end if\n \n return\n end\n subroutine r83t_mv ( m, n, a, x, b )\n\nc*********************************************************************72\nc\ncc R83T_MV multiplies an R83T matrix times an R8VEC.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 18 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, double precision A(M,3), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(M), the product A * x.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,3)\n double precision b(m)\n integer i\n integer mn\n double precision x(n)\n\n do i = 1, m\n b(i) = 0.0D+00\n end do\n\n mn = min ( m, n )\n\n if ( n .eq. 1 ) then\n b(1) = a(1,2) * x(1)\n if ( 1 .lt. m ) then\n b(2) = a(2,1) * x(1)\n end if\n return\n end if\n\n b(1) = a(1,2) * x(1) \n & + a(1,3) * x(2)\n\n do i = 2, mn - 1\n b(i) = a(i,1) * x(i-1) \n & + a(i,2) * x(i) \n & + a(i,3) * x(i+1)\n end do\n\n b(mn) = a(mn,1) * x(mn-1) \n & + a(mn,2) * x(mn)\n\n if ( n .lt. m ) then\n b(mn+1) = b(mn+1) + a(mn+1,1) * x(mn)\n else if ( m .lt. n ) then\n b(mn) = b(mn) + a(mn,3) * x(mn+1)\n end if\n\n return\n end\n subroutine r83t_resid ( m, n, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R83T_RESID computes the residual R = B-A*X for R83T matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 18 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, double precision A(M,3), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,3)\n double precision b(m)\n integer i\n double precision r(m)\n double precision x(n)\n\n call r83t_mv ( m, n, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r8ge_cg ( n, a, b, x )\n\nc*********************************************************************72\nc\ncc R8GE_CG uses the conjugate gradient method on an R8GE system.\nc\nc Discussion:\nc\nc The R8GE storage format is used for a general M by N matrix. A storage \nc space is made for each entry. The two dimensional logical\nc array can be thought of as a vector of M*N entries, starting with\nc the M entries in the column 1, then the M entries in column 2\nc and so on. Considered as a vector, the entry A(I,J) is then stored\nc in vector location I+(J-1)*M.\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, double precision A(N,N), the matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer n\n\n double precision a(n,n)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r8ge_mv ( n, n, a, x, ap )\n\n do i = 1, n \n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r8ge_mv ( n, n, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r8ge_dif2 ( m, n, a )\n\nc*********************************************************************72\nc\ncc R8GE_DIF2 returns the DIF2 matrix in R8GE format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 01 July 2000\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the order of the matrix.\nc\nc Output, double precision A(M,N), the matrix.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,n)\n integer i\n integer j\n\n do j = 1, n\n do i = 1, m\n\n if ( j .eq. i - 1 ) then\n a(i,j) = -1.0D+00\n else if ( j .eq. i ) then\n a(i,j) = 2.0D+00\n else if ( j .eq. i + 1 ) then\n a(i,j) = -1.0D+00\n else\n a(i,j) = 0.0D+00\n end if\n\n end do\n end do\n\n return\n end\n subroutine r8ge_mv ( m, n, a, x, b )\n\nc*********************************************************************72\nc\ncc R8GE_MV multiplies an R8GE matrix by an R8VEC.\nc\nc Discussion:\nc\nc The R8GE storage format is used for a general M by N matrix. A storage \nc space is made for each entry. The two dimensional logical\nc array can be thought of as a vector of M*N entries, starting with\nc the M entries in the column 1, then the M entries in column 2\nc and so on. Considered as a vector, the entry A(I,J) is then stored\nc in vector location I+(J-1)*M.\nc\nc R8GE storage is used by LINPACK and LAPACK.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 11 January 1999\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, double precision A(M,N), the R8GE matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(M), the product A * x.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,n)\n double precision b(m)\n double precision x(n)\n\n call r8mat_mv ( m, n, a, x, b )\n\n return\n end\n subroutine r8ge_resid ( m, n, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R8GE_RESID computes the residual R = B-A*X for R8GE matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, double precision A(M,N), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,n)\n double precision b(m)\n integer i\n double precision r(m)\n double precision x(n)\n\n call r8mat_mv ( m, n, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r8mat_house_axh ( n, a, v, ah )\n\nc*********************************************************************72\nc\ncc R8MAT_HOUSE_AXH computes A*H where H is a compact Householder matrix.\nc\nc Discussion:\nc\nc The Householder matrix H(V) is defined by\nc\nc H(V) = I - 2 * v * v' / ( v' * v )\nc\nc This routine is not particularly efficient.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 05 February 2008\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the order of A.\nc\nc Input, double precision A(N,N), the matrix.\nc\nc Input, double precision V(N), a vector defining a Householder matrix.\nc\nc Output, double precision AH(N,N), the product A*H.\nc\n implicit none\n\n integer n\n\n double precision a(n,n)\n double precision ah(n,n)\n double precision av(n)\n integer i\n integer j\n double precision v(n)\n double precision v_normsq\n\n v_normsq = 0.0D+00\n do i = 1, n\n v_normsq = v_normsq + v(i)**2\n end do\n \n do i = 1, n\n av(i) = 0.0D+00\n do j = 1, n\n av(i) = av(i) + a(i,j) * v(j)\n end do\n end do\n\n do i = 1, n\n do j = 1, n\n ah(i,j) = a(i,j)\n end do\n end do\n\n do i = 1, n\n do j = 1, n\n ah(i,j) = ah(i,j) - 2.0D+00 * av(i) * v(j)\n end do\n end do\n\n do i = 1, n\n do j = 1, n\n ah(i,j) = ah(i,j) / v_normsq\n end do\n end do\n\n return\n end\n subroutine r8mat_mv ( m, n, a, x, y )\n\nc*********************************************************************72\nc\ncc R8MAT_MV multiplies a matrix times a vector.\nc\nc Discussion:\nc\nc An R8MAT is an array of R8's.\nc\nc In FORTRAN90, this operation can be more efficiently carried\nc out by the command\nc\nc Y(1:M) = MATMUL ( A(1:M,1:N), X(1:N) )\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 12 December 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns of the matrix.\nc\nc Input, double precision A(M,N), the M by N matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision Y(M), the product A*X.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,n)\n integer i\n integer j\n double precision x(n)\n double precision y(m)\n double precision y1(m)\n\n do i = 1, m\n y1(i) = 0.0D+00\n do j = 1, n\n y1(i) = y1(i) + a(i,j) * x(j)\n end do\n end do\n\n do i = 1, m\n y(i) = y1(i)\n end do\n\n return\n end\n subroutine r8mat_print ( m, n, a, title )\n\nc*********************************************************************72\nc\ncc R8MAT_PRINT prints an R8MAT.\nc\nc Discussion:\nc\nc An R8MAT is an array of R8's.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 20 May 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows in A.\nc\nc Input, integer N, the number of columns in A.\nc\nc Input, double precision A(M,N), the matrix.\nc\nc Input, character ( len = * ) TITLE, a title.\nc\n implicit none\n\n integer m\n integer n\n\n double precision a(m,n)\n character ( len = * ) title\n\n call r8mat_print_some ( m, n, a, 1, 1, m, n, title )\n\n return\n end\n subroutine r8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi,\n & title )\n\nc*********************************************************************72\nc\ncc R8MAT_PRINT_SOME prints some of an R8MAT.\nc\nc Discussion:\nc\nc An R8MAT is an array of R8's.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 25 January 2007\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, double precision A(M,N), an M by N matrix to be printed.\nc\nc Input, integer ILO, JLO, the first row and column to print.\nc\nc Input, integer IHI, JHI, the last row and column to print.\nc\nc Input, character ( len = * ) TITLE, a title.\nc\n implicit none\n\n integer incx\n parameter ( incx = 5 )\n integer m\n integer n\n\n double precision a(m,n)\n character * ( 14 ) ctemp(incx)\n integer i\n integer i2hi\n integer i2lo\n integer ihi\n integer ilo\n integer inc\n integer j\n integer j2\n integer j2hi\n integer j2lo\n integer jhi\n integer jlo\n character * ( * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n\n if ( m .le. 0 .or. n .le. 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), '(i7,7x)') j\n end do\n\n write ( *, '('' Col '',5a14)' ) ( ctemp(j), j = 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 write ( ctemp(j2), '(g14.6)' ) a(i,j)\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\n end\n subroutine r8pbu_cg ( n, mu, a, b, x )\n\nc*********************************************************************72\nc\ncc R8PBU_CG uses the conjugate gradient method on an R8PBU system.\nc\nc Discussion:\nc\nc The R8PBU storage format is for a symmetric positive definite band matrix.\nc\nc To save storage, only the diagonal and upper triangle of A is stored,\nc in a compact diagonal format that preserves columns.\nc\nc The diagonal is stored in row MU+1 of the array.\nc The first superdiagonal in row MU, columns 2 through N.\nc The second superdiagonal in row MU-1, columns 3 through N.\nc The MU-th superdiagonal in row 1, columns MU+1 through N.\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 15 October 1998\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, integer MU, the number of superdiagonals.\nc MU must be at least 0, and no more than N-1.\nc\nc Input, double precision A(MU+1,N), the R8PBU matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer mu\n integer n\n\n double precision a(mu+1,n)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r8pbu_mv ( n, n, mu, a, x, ap )\n\n do i = 1, n \n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r8pbu_mv ( n, n, mu, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r8pbu_dif2 ( m, n, mu, a )\n\nc*********************************************************************72\nc\ncc R8PBU_DIF2 returns the DIF2 matrix in R8PBU format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 01 July 2000\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, integer MU, the number of superdiagonals.\nc MU must be at least 0, and no more than N-1.\nc\nc Output, double precision A(MU+1,N), the matrix.\nc\n implicit none\n\n integer mu\n integer n\n\n double precision a(mu+1,n)\n integer i\n integer j\n integer m\n\n do j = 1, n\n do i = 1, mu + 1\n a(i,j) = 0.0D+00\n end do\n end do\n\n do j = 2, n\n a(mu,j) = -1.0D+00\n end do\n\n do j = 1, n\n a(mu+1,j) = +2.0D+00\n end do\n \n return\n end\n subroutine r8pbu_mv ( m, n, mu, a, x, b )\n\nc*********************************************************************72\nc\ncc R8PBU_MV multiplies an R8PBU matrix by an R8VEC.\nc\nc Discussion:\nc\nc The R8PBU storage format is for a symmetric positive definite band matrix.\nc\nc To save storage, only the diagonal and upper triangle of A is stored,\nc in a compact diagonal format that preserves columns.\nc\nc The diagonal is stored in row MU+1 of the array.\nc The first superdiagonal in row MU, columns 2 through N.\nc The second superdiagonal in row MU-1, columns 3 through N.\nc The MU-th superdiagonal in row 1, columns MU+1 through N.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 15 October 1998\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, integer MU, the number of superdiagonals in the matrix.\nc MU must be at least 0 and no more than N-1.\nc\nc Input, double precision A(MU+1,N), the R8PBU matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(N), the result vector A * x.\nc\n implicit none\n\n integer mu\n integer n\n\n double precision a(mu+1,n)\n double precision b(n)\n integer i\n integer ieqn\n integer j\n integer m\n double precision x(n)\nc\nc Multiply X by the diagonal of the matrix.\nc\n do j = 1, n\n b(j) = a(mu+1,j) * x(j)\n end do\nc\nc Multiply X by the superdiagonals of the matrix.\nc\n do i = mu, 1, -1\n do j = mu + 2 - i, n\n ieqn = i + j - mu - 1\n b(ieqn) = b(ieqn) + a(i,j) * x(j)\n b(j) = b(j) + a(i,j) * x(ieqn)\n end do\n end do\n\n return\n end\n subroutine r8pbu_resid ( m, n, mu, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R8PBU_RESID computes the residual R = B-A*X for R8PBU matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, integer MU, the number of superdiagonals in the matrix.\nc MU must be at least 0 and no more than N-1.\nc\nc Input, double precision A(MU+1,N), the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer mu\n integer n\n\n double precision a(mu+1,n)\n double precision b(m)\n integer i\n double precision r(m)\n double precision x(n)\n\n call r8pbu_mv ( m, n, mu, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r8sd_cg ( n, ndiag, offset, a, b, x )\n\nc*********************************************************************72\nc\ncc R8SD_CG uses the conjugate gradient method on an R8SD linear system.\nc\nc Discussion:\nc\nc The R8SD storage format is for symmetric matrices whose only nonzero\nc entries occur along a few diagonals, but for which these diagonals are \nc not all close enough to the main diagonal for band storage to be efficient.\nc\nc In that case, we assign the main diagonal the offset value 0, and \nc each successive superdiagonal gets an offset value 1 higher, until\nc the highest superdiagonal (the A(1,N) entry) is assigned the offset N-1.\nc\nc Assuming there are NDIAG nonzero diagonals (ignoring subdiagonals!),\nc we then create an array B that has N rows and NDIAG columns, and simply\nc \"collapse\" the matrix A to the left:\nc\nc For the conjugate gradient method to be applicable, the matrix A must \nc be a positive definite symmetric matrix.\nc\nc The method is designed to reach the solution to the linear system\nc A * x = b\nc after N computational steps. However, roundoff may introduce\nc unacceptably large errors for some problems. In such a case,\nc calling the routine a second time, using the current solution estimate\nc as the new starting guess, should result in improved results.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 15 October 1998\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, integer NDIAG, the number of diagonals that are stored.\nc NDIAG must be at least 1 and no more than N.\nc\nc Input, integer OFFSET(NDIAG), the offsets for the diagonal\nc storage.\nc\nc Input, double precision A(N,NDIAG), the R8SD matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector. Note that repeated\nc calls to this routine, using the value of X output on the previous\nc call, MAY improve the solution.\nc\n implicit none\n\n integer n\n integer ndiag\n\n double precision a(n,ndiag)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer i\n integer it\n integer m\n integer offset(ndiag)\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r8sd_mv ( n, n, ndiag, offset, a, x, ap )\n\n do i = 1, n \n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP = A*P.\nc\n call r8sd_mv ( n, n, ndiag, offset, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r8sd_dif2 ( m, n, ndiag, offset, a )\n\nc*********************************************************************72\nc\ncc R8SD_DIF2 returns the DIF2 matrix in R8SD format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 01 July 2000\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, integer NDIAG, the number of diagonals that are stored.\nc NDIAG must be at least 1 and no more than N.\nc\nc Input, integer OFFSET(NDIAG), the offsets for the diagonal\nc storage. It is simply assumed that OFFSET(1) = 0 and OFFSET(2) = 1.\nc\nc Output, double precision A(N,NDIAG), the R8SD matrix.\nc\n implicit none\n\n integer n\n integer ndiag\n\n double precision a(n,ndiag)\n integer i\n integer j\n integer m\n integer offset(ndiag)\n\n do j = 1, ndiag\n do i = 1, n\n a(i,j) = 0.0D+00\n end do\n end do\n\n do i = 1, n\n a(i,1) = 2.0D+00\n end do\n\n do i = 1, n - 1\n a(i,2) = -1.0D+00\n end do\n \n return\n end\n subroutine r8sd_mv ( m, n, ndiag, offset, a, x, b )\n\nc*********************************************************************72\nc\ncc R8SD_MV multiplies an R8SD matrix by an R8VEC.\nc\nc Discussion:\nc\nc The R8SD storage format is for symmetric matrices whose only nonzero \nc entries occur along a few diagonals, but for which these diagonals are not \nc all close enough to the main diagonal for band storage to be efficient.\nc\nc In that case, we assign the main diagonal the offset value 0, and \nc each successive superdiagonal gets an offset value 1 higher, until\nc the highest superdiagonal (the A(1,N) entry) is assigned the offset N-1.\nc\nc Assuming there are NDIAG nonzero diagonals (ignoring subdiagonals!),\nc we then create an array B that has N rows and NDIAG columns, and simply\nc \"collapse\" the matrix A to the left:\nc\nc Example:\nc\nc The \"offset\" value is printed above each column.\nc\nc Original matrix New Matrix\nc\nc 0 1 2 3 4 5 0 1 3 5\nc\nc 11 12 0 14 0 16 11 12 14 16\nc 21 22 23 0 25 0 22 23 25 --\nc 0 32 33 34 0 36 33 34 36 --\nc 41 0 43 44 45 0 44 45 -- --\nc 0 52 0 54 55 56 55 56 -- --\nc 61 0 63 0 65 66 66 -- -- --\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 15 October 1998\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, integer NDIAG, the number of diagonals that are stored.\nc NDIAG must be at least 1 and no more than N.\nc\nc Input, integer OFFSET(NDIAG), the offsets for the diagonal\nc storage.\nc\nc Input, double precision A(N,NDIAG), the R8SD matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(N), the product A * x.\nc\n implicit none\n\n integer m\n integer n\n integer ndiag\n\n double precision a(n,ndiag)\n double precision b(n)\n integer i\n integer j\n integer jdiag\n integer offset(ndiag)\n double precision x(n)\n\n do i = 1, n\n b(i) = 0.0D+00\n end do\n\n do i = 1, n\n do jdiag = 1, ndiag\n if ( 0 .le. offset(jdiag) ) then\n j = i + offset(jdiag)\n if ( 1 .le. j .and. j .le. n ) then\n b(i) = b(i) + a(i,jdiag) * x(j)\n if ( offset(jdiag) .ne. 0 ) then\n b(j) = b(j) + a(i,jdiag) * x(i)\n end if\n end if\n end if\n end do\n end do\n\n return\n end\n subroutine r8sd_resid ( m, n, ndiag, offset, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R8SD_RESID computes the residual R = B-A*X for R8SD matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, integer NDIAG, the number of diagonals that are stored.\nc NDIAG must be at least 1 and no more than N.\nc\nc Input, integer OFFSET(NDIAG), the offsets for the diagonal\nc storage.\nc\nc Input, double precision A(N,NDIAG), the R8SD matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n integer ndiag\n\n double precision a(n,ndiag)\n double precision b(m)\n integer i\n integer offset(ndiag)\n double precision r(m)\n double precision x(n)\n\n call r8sd_mv ( m, n, ndiag, offset, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n subroutine r8sp_cg ( n, nz_num, row, col, a, b, x )\n\nc*********************************************************************72\nc\ncc R8SP_CG uses the conjugate gradient method on an R8SP system.\nc\nc Discussion:\nc\nc The R8SP storage format stores the row, column and value of each nonzero\nc entry of a sparse matrix.\nc\nc It is possible that a pair of indices (I,J) may occur more than\nc once. Presumably, in this case, the intent is that the actual value\nc of A(I,J) is the sum of all such entries. This is not a good thing\nc to do, but I seem to have come across this in MATLAB.\nc\nc The R8SP format is used by CSPARSE (\"sparse triplet\"), DLAP/SLAP \nc (\"nonsymmetric SLAP triad\"), by MATLAB, and by SPARSEKIT (\"COO\" format).\nc\nc The matrix A must be a positive definite symmetric band matrix.\nc\nc The method is designed to reach the solution after N computational\nc steps. However, roundoff may introduce unacceptably large errors for\nc some problems. In such a case, calling the routine again, using\nc the computed solution as the new starting estimate, should improve\nc the results.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Frank Beckman,\nc The Solution of Linear Equations by the Conjugate Gradient Method,\nc in Mathematical Methods for Digital Computers,\nc edited by John Ralston, Herbert Wilf,\nc Wiley, 1967,\nc ISBN: 0471706892,\nc LC: QA76.5.R3.\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix.\nc N must be positive.\nc\nc Input, integer NZ_NUM, the number of nonzero elements in\nc the matrix.\nc\nc Input, integer ROW(NZ_NUM), COL(NZ_NUM), the row and \nc column indices of the nonzero elements.\nc\nc Input, double precision A(NZ_NUM), the nonzero elements of the matrix.\nc\nc Input, double precision B(N), the right hand side vector.\nc\nc Input/output, double precision X(N).\nc On input, an estimate for the solution, which may be 0.\nc On output, the approximate solution vector.\nc\n implicit none\n\n integer n\n integer nz_num\n\n double precision a(nz_num)\n double precision alpha\n double precision ap(n)\n double precision b(n)\n double precision beta\n integer col(nz_num)\n integer i\n integer it\n double precision p(n)\n double precision pap\n double precision pr\n double precision r(n)\n double precision r8vec_dot_product\n integer row(nz_num)\n double precision rap\n double precision x(n)\nc\nc Initialize\nc AP = A * x,\nc R = b - A * x,\nc P = b - A * x.\nc\n call r8sp_mv ( n, n, nz_num, row, col, a, x, ap )\n\n do i = 1, n \n r(i) = b(i) - ap(i)\n end do\n\n do i = 1, n\n p(i) = b(i) - ap(i)\n end do\nc\nc Do the N steps of the conjugate gradient method.\nc\n do it = 1, n\nc\nc Compute the matrix*vector product AP=A*P.\nc\n call r8sp_mv ( n, n, nz_num, row, col, a, p, ap )\nc\nc Compute the dot products\nc PAP = P*AP,\nc PR = P*R\nc Set\nc ALPHA = PR / PAP.\nc\n pap = r8vec_dot_product ( n, p, ap )\n pr = r8vec_dot_product ( n, p, r )\n\n if ( pap .eq. 0.0D+00 ) then\n return\n end if\n\n alpha = pr / pap\nc\nc Set\nc X = X + ALPHA * P\nc R = R - ALPHA * AP.\nc\n do i = 1, n\n x(i) = x(i) + alpha * p(i)\n end do\n\n do i = 1, n\n r(i) = r(i) - alpha * ap(i)\n end do\nc\nc Compute the vector dot product\nc RAP = R*AP\nc Set\nc BETA = - RAP / PAP.\nc\n rap = r8vec_dot_product ( n, r, ap )\n\n beta = - rap / pap\nc\nc Update the perturbation vector\nc P = R + BETA * P.\nc\n do i = 1, n\n p(i) = r(i) + beta * p(i)\n end do\n\n end do\n\n return\n end\n subroutine r8sp_dif2 ( m, n, nz_num, row, col, a )\n\nc*********************************************************************72\nc\ncc R8SP_DIF2 returns the DIF2 matrix in R8SP format.\nc\nc Example:\nc\nc N = 5\nc\nc 2 -1 . . .\nc -1 2 -1 . .\nc . -1 2 -1 .\nc . . -1 2 -1\nc . . . -1 2\nc\nc Properties:\nc\nc A is banded, with bandwidth 3.\nc\nc A is tridiagonal.\nc\nc Because A is tridiagonal, it has property A (bipartite).\nc\nc A is a special case of the TRIS or tridiagonal scalar matrix.\nc\nc A is integral, therefore det ( A ) is integral, and \nc det ( A ) * inverse ( A ) is integral.\nc\nc A is Toeplitz: constant along diagonals.\nc\nc A is symmetric: A' = A.\nc\nc Because A is symmetric, it is normal.\nc\nc Because A is normal, it is diagonalizable.\nc\nc A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\nc\nc A is positive definite.\nc\nc A is an M matrix.\nc\nc A is weakly diagonally dominant, but not strictly diagonally dominant.\nc\nc A has an LU factorization A = L * U, without pivoting.\nc\nc The matrix L is lower bidiagonal with subdiagonal elements:\nc\nc L(I+1,I) = -I/(I+1)\nc\nc The matrix U is upper bidiagonal, with diagonal elements\nc\nc U(I,I) = (I+1)/I\nc\nc and superdiagonal elements which are all -1.\nc\nc A has a Cholesky factorization A = L * L', with L lower bidiagonal.\nc\nc L(I,I) = sqrt ( (I+1) / I )\nc L(I,I-1) = -sqrt ( (I-1) / I )\nc\nc The eigenvalues are\nc\nc LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\nc = 4 SIN^2(I*PI/(2*N+2))\nc\nc The corresponding eigenvector X(I) has entries\nc\nc X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\nc\nc Simple linear systems:\nc\nc x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\nc\nc x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\nc\nc det ( A ) = N + 1.\nc\nc The value of the determinant can be seen by induction,\nc and expanding the determinant across the first row:\nc\nc det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\nc = 2 * N - (N-1)\nc = N + 1\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 01 July 2000\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Robert Gregory, David Karney,\nc A Collection of Matrices for Testing Computational Algorithms,\nc Wiley, 1969,\nc ISBN: 0882756494,\nc LC: QA263.68\nc\nc Morris Newman, John Todd,\nc Example A8,\nc The evaluation of matrix inversion programs,\nc Journal of the Society for Industrial and Applied Mathematics,\nc Volume 6, Number 4, pages 466-476, 1958.\nc\nc John Todd,\nc Basic Numerical Mathematics,\nc Volume 2: Numerical Algebra,\nc Birkhauser, 1980,\nc ISBN: 0817608117,\nc LC: QA297.T58.\nc\nc Joan Westlake,\nc A Handbook of Numerical Matrix Inversion and Solution of \nc Linear Equations,\nc John Wiley, 1968,\nc ISBN13: 978-0471936756,\nc LC: QA263.W47.\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns.\nc\nc Input, integer NZ_NUM, the number of nonzero elements in\nc the matrix.\nc\nc Output, integer ROW(NZ_NUM), COL(NZ_NUM), the row and \nc column indices of the nonzero elements.\nc\nc Output, double precision A(NZ_NUM), the nonzero elements of the matrix.\nc\n implicit none\n\n integer n\n integer nz_num\n\n double precision a(nz_num)\n integer col(nz_num)\n integer i\n integer k\n integer m\n integer row(nz_num)\n\n k = 0\n do i = 1, m\n\n if ( 0 .lt. i - 1 ) then\n k = k + 1\n row(k) = i\n col(k) = i - 1\n a(k) = -1.0D+00\n end if\n\n k = k + 1\n row(k) = i\n col(k) = i\n a(k) = 2.0D+00\n\n if ( i .lt. n ) then\n k = k + 1\n row(k) = i\n col(k) = i + 1\n a(k) = -1.0D+00\n end if\n\n end do\n\n return\n end\n subroutine r8sp_mv ( m, n, nz_num, row, col, a, x, b )\n\nc*********************************************************************72\nc\ncc R8SP_MV multiplies an R8SP matrix by an R8VEC.\nc\nc Discussion:\nc\nc The R8SP storage format stores the row, column and value of each nonzero\nc entry of a sparse matrix.\nc\nc It is possible that a pair of indices (I,J) may occur more than\nc once. Presumably, in this case, the intent is that the actual value\nc of A(I,J) is the sum of all such entries. This is not a good thing\nc to do, but I seem to have come across this in MATLAB.\nc\nc The R8SP format is used by CSPARSE (\"sparse triplet\"), DLAP/SLAP \nc (\"nonsymmetric SLAP triad\"), by MATLAB, and by SPARSEKIT (\"COO\" format).\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 21 January 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, N, the number of rows and columns of \nc the matrix.\nc\nc Input, integer NZ_NUM, the number of nonzero elements in\nc the matrix.\nc\nc Input, integer ROW(NZ_NUM), COL(NZ_NUM), the row and \nc column indices of the nonzero elements.\nc\nc Input, double precision A(NZ_NUM), the nonzero elements of the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Output, double precision B(M), the product vector A*X.\nc\n implicit none\n\n integer m\n integer n\n integer nz_num\n\n double precision a(nz_num)\n double precision b(m)\n integer col(nz_num)\n integer i\n integer j\n integer k\n integer row(nz_num)\n double precision x(n)\n\n do i = 1, m\n b(i) = 0.0D+00\n end do\n\n do k = 1, nz_num\n\n i = row(k)\n j = col(k)\n b(i) = b(i) + a(k) * x(j)\n\n end do\n\n return\n end\n subroutine r8sp_resid ( m, n, nz_num, row, col, a, x, b, r )\n\nc*********************************************************************72\nc\ncc R8SP_RESID computes the residual R = B-A*X for R8SP matrices.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license. \nc\nc Modified:\nc\nc 02 June 2014\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer M, the number of rows of the matrix.\nc M must be positive.\nc\nc Input, integer N, the number of columns of the matrix.\nc N must be positive.\nc\nc Input, integer NZ_NUM, the number of nonzero elements in\nc the matrix.\nc\nc Input, integer ROW(NZ_NUM), COL(NZ_NUM), the row and \nc column indices of the nonzero elements.\nc\nc Input, double precision A(NZ_NUM), the nonzero elements of the matrix.\nc\nc Input, double precision X(N), the vector to be multiplied by A.\nc\nc Input, double precision B(M), the desired result A * x.\nc\nc Output, double precision R(M), the residual R = B - A * X.\nc\n implicit none\n\n integer m\n integer n\n integer nz_num\n\n double precision a(nz_num)\n double precision b(m)\n integer col(nz_num)\n integer i\n double precision r(m)\n integer row(nz_num)\n double precision x(n)\n\n call r8sp_mv ( m, n, nz_num, row, col, a, x, r )\n\n do i = 1, m\n r(i) = b(i) - r(i)\n end do\n\n return\n end\n function r8vec_diff_norm ( n, a, b )\n\nc*********************************************************************72\nc\ncc R8VEC_DIFF_NORM returns the L2 norm of the difference of R8VEC's.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8 values.\nc\nc The vector L2 norm is defined as:\nc\nc R8VEC_NORM_L2 = sqrt ( sum ( 1 .le. I .le. N ) A(I)^2 ).\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 24 June 2010\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in A.\nc\nc Input, double precision A(N), B(N), the vectors.\nc\nc Output, double precision R8VEC_DIFF_NORM, the L2 norm of A - B.\nc\n implicit none\n\n integer n\n\n double precision a(n)\n double precision b(n)\n integer i\n double precision r8vec_diff_norm\n double precision value\n\n value = 0.0D+00\n do i = 1, n\n value = value + ( a(i) - b(i) )**2\n end do\n value = sqrt ( value )\n\n r8vec_diff_norm = value\n\n return\n end\n function r8vec_dot_product ( n, v1, v2 )\n\nc*********************************************************************72\nc\ncc R8VEC_DOT_PRODUCT finds the dot product of a pair of R8VEC's.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8 values.\nc\nc In FORTRAN90, the system routine DOT_PRODUCT should be called\nc directly.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 27 May 2008\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the dimension of the vectors.\nc\nc Input, double precision V1(N), V2(N), the vectors.\nc\nc Output, double precision R8VEC_DOT_PRODUCT, the dot product.\nc\n implicit none\n\n integer n\n\n integer i\n double precision r8vec_dot_product\n double precision v1(n)\n double precision v2(n)\n double precision value\n\n value = 0.0D+00\n do i = 1, n\n value = value + v1(i) * v2(i)\n end do\n\n r8vec_dot_product = value\n\n return\n end\n subroutine r8vec_house_column ( n, a, k, v )\n\nc*********************************************************************72\nc\ncc R8VEC_HOUSE_COLUMN defines a Householder premultiplier that \"packs\" a column.\nc\nc Discussion:\nc\nc The routine returns a vector V that defines a Householder\nc premultiplier matrix H(V) that zeros out the subdiagonal entries of\nc column K of the matrix A.\nc\nc H(V) = I - 2 * v * v'\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 05 February 2008\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, integer N, the order of the matrix A.\nc\nc Input, double precision A(N), column K of the matrix A.\nc\nc Input, integer K, the column of the matrix to be modified.\nc\nc Output, double precision V(N), a vector of unit L2 norm which defines an\nc orthogonal Householder premultiplier matrix H with the property\nc that the K-th column of H*A is zero below the diagonal.\nc\n implicit none\n\n integer n\n\n double precision a(n)\n integer i\n integer k\n double precision s\n double precision v(n)\n double precision vnorm\n\n do i = 1, n\n v(i) = 0.0D+00\n end do\n\n if ( k .lt. 1 .or. n .le. k ) then\n return\n end if\n\n s = 0.0D+00\n do i = k, n\n s = s + a(i)**2\n end do\n s = sqrt ( s )\n\n if ( s .eq. 0.0D+00 ) then\n return\n end if\n\n v(k) = a(k) + sign ( s, a(k) )\n do i = k + 1, n\n v(i) = a(i)\n end do\n\n vnorm = 0.0D+00\n do i = k, n\n vnorm = vnorm + v(i) * v(i)\n end do\n vnorm = sqrt ( vnorm )\n\n do i = k, n\n v(i) = v(i) / vnorm\n end do\n\n return\n end\n function r8vec_norm ( n, a )\n\nc*********************************************************************72\nc\ncc R8VEC_NORM returns the L2 norm of an R8VEC.\nc\nc Discussion:\nc\nc An R8VEC is a vector of R8 values.\nc\nc The vector L2 norm is defined as:\nc\nc R8VEC_NORM = sqrt ( sum ( 1 .le. I .le. N ) A(I)^2 ).\nc\nc Licensing:\nc\nc This code is distributed under the MIT license.\nc\nc Modified:\nc\nc BY Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in A.\nc\nc Input, double precision A(N), the vector whose L2 norm is desired.\nc\nc Output, double precision R8VEC_NORM, the L2 norm of A.\nc\n implicit none\n\n integer n\n\n double precision a(n)\n integer i\n double precision r8vec_norm\n double precision value\n\n value = 0.0D+00\n do i = 1, n\n value = value + a(i) * a(i)\n end do\n value = sqrt ( value )\n\n r8vec_norm = value\n\n return\n end\n subroutine r8vec_print ( n, a, title )\n\nc*********************************************************************72\nc\ncc R8VEC_PRINT prints an 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 MIT license.\nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\nc Parameters:\nc\nc Input, integer N, the number of components of the vector.\nc\nc Input, double precision A(N), the vector to be printed.\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 character ( len = * ) title\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i8,a,1x,g16.8)' ) i, ':', a(i)\n end do\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 MIT license.\nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\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 timestamp ( )\n\nc*********************************************************************72\nc\ncc TIMESTAMP prints out the current YMDHMS date as a timestamp.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license.\nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\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": "be4865848976475fa802d33dc4f444c0cbcbf0be", "size": 96517, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cg.f", "max_stars_repo_name": "FortranSoftwares/Conjugate-Gradient-Solver-for-Linear-Systems", "max_stars_repo_head_hexsha": "25691f24c71b5c6aba0edd2617ed6c268da55e12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-27T18:24:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T16:54:15.000Z", "max_issues_repo_path": "cg.f", "max_issues_repo_name": "FortranSoftwares/Conjugate-Gradient-Solver-for-Linear-Systems", "max_issues_repo_head_hexsha": "25691f24c71b5c6aba0edd2617ed6c268da55e12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cg.f", "max_forks_repo_name": "FortranSoftwares/Conjugate-Gradient-Solver-for-Linear-Systems", "max_forks_repo_head_hexsha": "25691f24c71b5c6aba0edd2617ed6c268da55e12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-02T19:06:48.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-02T19:06:48.000Z", "avg_line_length": 22.4981351981, "max_line_length": 80, "alphanum_fraction": 0.5775148419, "num_tokens": 31220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.8014213331276107}} {"text": "! newton.f90 --\n!\n! Example belonging to \"Modern Fortran in Practice\" by Arjen Markus\n!\n! This work is licensed under the Creative Commons Attribution 3.0\n! Unported License.\n! To view a copy of this license, visit\n! http://creativecommons.org/licenses/by/3.0/\n! or send a letter to:\n! Creative Commons, 444 Castro Street, Suite 900, Mountain View,\n! California, 94041, USA.\n!\n! Straightforward implementation of the Newton-Raphson method\n! for finding roots of an equation\n!\nmodule newton_raphson\n\n implicit none\n\ncontains\n\nsubroutine find_root( f, xinit, tol, maxiter, result, success )\n\n interface\n real function f(x)\n real, intent(in) :: x\n end function f\n end interface\n\n real, intent(in) :: xinit\n real, intent(in) :: tol\n integer, intent(in) :: maxiter\n real, intent(out) :: result\n logical, intent(out) :: success\n\n real :: eps = 1.0e-4\n real :: fx1\n real :: fx2\n real :: fprime\n real :: x\n real :: xnew\n integer :: i\n\n result = 0.0\n success = .false.\n\n x = xinit\n do i = 1,max(1,maxiter)\n fx1 = f(x)\n fx2 = f(x+eps)\n write(*,*) i, fx1, fx2, eps\n fprime = (fx2 - fx1) / eps\n\n xnew = x - fx1 / fprime\n\n if ( abs(xnew-x) <= tol ) then\n success = .true.\n result = xnew\n exit\n endif\n\n x = xnew\n write(*,*) i, x\n enddo\n\nend subroutine find_root\n\nend module\n\nmodule functions\n implicit none\n\ncontains\nreal function f1( x )\n real, intent(in) :: x\n\n f1 = exp(x) + x ! exp(x)-x is also interesting\nend function\n\nreal function f2( x )\n real, intent(in) :: x\n\n f2 = x**2 + 1.0\nend function\n\nreal function f3( x )\n real, intent(in) :: x\n\n ! f3 = sqrt(abs(x)) + 1.0 - cycle: 12.4 -- -130.08\n ! f3 = sqrt(abs(x)) + 0.1 - slow divergence\n ! f3 = sqrt(abs(x)) + 0.001 - cycle: 1.003 -- 1.004 -- 1.003 --\n ! -1.004\n f3 = sqrt(abs(x)) + 0.001\n\nend function\n\nreal function f4( x )\n real, intent(in) :: x\n\n f4 = abs(x) ** 0.3333\n if ( x > 0.0 ) then\n f4 = f4 - 1.0\n else\n f4 = -f4 - 1.0\n endif\n\nend function\n\nreal function fln( x )\n real, intent(in) :: x\n\n fln = log(x) - 1.0\n\nend function\n\nreal function fparabola( x )\n real, intent(in) :: x\n\n fparabola = x ** 2\n\nend function\n\nreal function fparabola2( x )\n real, intent(in) :: x\n\n fparabola2 = x ** 2 + 1.0\n\nend function\n\nreal function fsqrt( x )\n real, intent(in) :: x\n\n fsqrt = sqrt(abs(x))\n\nend function\n\n\nend module\n\nprogram test_newton\n use newton_raphson\n use functions\n\n implicit none\n\n real :: x\n real :: root\n integer :: maxiter = 20\n logical :: success\n\n write(*,*) 'fln: 0.1'\n x = 0.1\n call find_root( fln, x, 1.0e-5, maxiter, root, success )\n write(*,*) root, fln(root), success\n\n write(*,*) 'fln: 10.0'\n x = 10.0\n call find_root( fln, x, 1.0e-5, maxiter, root, success )\n write(*,*) root, fln(root), success\n\n write(*,*) 'fparabola: 10.0'\n x = 10.0\n call find_root( fparabola, x, 1.0e-5, maxiter, root, success )\n write(*,*) root, fparabola(root), success\n\n write(*,*) 'fparabola2: 10.0'\n x = 10.0\n call find_root( fparabola2, x, 1.0e-5, maxiter, root, success )\n write(*,*) root, fparabola2(root), success\n\n write(*,*) 'fsqrt: 1.0'\n x = 1.0\n call find_root( fsqrt, x, 1.0e-5, maxiter, root, success )\n write(*,*) root, fsqrt(root), success\n\n!\n! x = -2.0 ! x = 2.0 works, -2.0 does not\n! call find_root( f4, x, 1.0e-5, maxiter, root, success )\n!\n! write(*,*) root, f4(root), success\n!\nend program test_newton\n", "meta": {"hexsha": "78b749f979534d9540ed73d581b57676510df8b4", "size": 3830, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "newtonsMethod/fortran/newton.f90", "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/newton.f90", "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/newton.f90", "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": 20.9289617486, "max_line_length": 71, "alphanum_fraction": 0.5425587467, "num_tokens": 1293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.8014067615837874}} {"text": "! HOW TO COMPILE THROUGH COMMAND LINE (CMD OR TERMINAL)\n! gfortran -c euler.f95\n! gfortran -o euler euler.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\n!\n! email: auliakhalqillah.mail@gmail.com\n! ==============================================================================\n\nprogram euler\n implicit none\n\n real :: x, y, h, df,fa\n real :: i, n, xi, xf, error\n character(len=100) :: fmt\n\n write(*,*)\"\"\n write(*,*)\"---------------------------------\"\n write(*,*)\"EULER METHOD - INTEGRATION\"\n write(*,*)\"---------------------------------\"\n write(*,*) \"\"\n write(*,\"(a)\",advance='no') \"INSERT INITIAL BOUNDARY:\"\n read *, xi\n write(*,\"(a)\",advance='no') \"INSERT FINAL BOUNDARY:\"\n read *, xf\n write(*,\"(a)\",advance='no') \"INSERT STEP OF DATA (EX:0.1):\"\n read*, h\n\n n = abs(xf - xi)/h\n\n x = xi\n y = 1\n i = 1\n fmt = \"(a12,a13,a22,a19,a15)\"\n write(*,*)\"\"\n write(*,fmt)\"X DATA\",\"dF(X)\",\"Analytic Int\",\"Numeric Int\",\"Error(%)\"\n open (1, file='euler.txt', status='replace')\n do while (i <= n)\n ! first differential equation\n df = 2 - (exp(-4*x)) - (2*y)\n\n ! analytic integral (original function)\n fa = 1 + (0.5*exp(-4*x)) - (0.5*exp(-2*x))\n\n ! Error calculation\n error = (abs(fa-y)/fa)*100\n\n write(1,*) x,df,fa,y,error\n write(*,*) x,df,fa,y,error\n ! Euler calculation\n y = y + (df*h)\n\n x = x + h\n i = i + 1\n end do\n close(1)\nend program\n", "meta": {"hexsha": "ea02122bcbde6fee69d4bf742b94c752cc25ac74", "size": 1459, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "euler.f95", "max_stars_repo_name": "auliakhalqillah/Numerical-Integration-Euler-Method", "max_stars_repo_head_hexsha": "f9c5e8c0874e91a74ee0e3cf6dc0098bf33af885", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "euler.f95", "max_issues_repo_name": "auliakhalqillah/Numerical-Integration-Euler-Method", "max_issues_repo_head_hexsha": "f9c5e8c0874e91a74ee0e3cf6dc0098bf33af885", "max_issues_repo_licenses": ["MIT"], "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.f95", "max_forks_repo_name": "auliakhalqillah/Numerical-Integration-Euler-Method", "max_forks_repo_head_hexsha": "f9c5e8c0874e91a74ee0e3cf6dc0098bf33af885", "max_forks_repo_licenses": ["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.7288135593, "max_line_length": 80, "alphanum_fraction": 0.5181631254, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.8013205863292533}} {"text": "module twave\n use setup\n implicit none\n !This contains functions used in the main routine\n !Created by: Enrique Hurtado\n !Date: 15 April 2019\n !Latest update: 15 April 2019\n !History:\n !Date: 04/15/19 || Mod: Program written || By: Enrique Hurtado\n !Purpose:\n !Specification: \n !Notes:\n !!Code Begins!!\n contains\n function hermite(x,n)\n integer :: n, i\n real(dp) :: x, hermite, hp(0:n)\n\n hp = 0._dp\n\n hp(0) = 1._dp\n hp(1) = 2._dp*x\n\n do i = 0, n-2\n hp(i+2) = 2._dp*x*hp(i+1) - 2._dp*(i+1)*hp(i)\n end do\n\n hermite = hp(n)\n\n end function\n\n function omega(z)\n real(dp) :: omega, z\n\n omega = w0*w0*(1.0 + (z*z)/(z0*z0))\n end function\n\n function R(z)\n real(dp) :: R, z\n\n R = z*(1.0 + (z0*z0)/(z*z))\n end function\n\n function Eta(z)\n real(dp) :: Eta, z\n\n Eta = atan(z/z0)\n end function\n\n function Ep(x,y,z)\n real(dp) :: Ep, x, y, z\n\n Ep = E0*(w0/omega(z))*hermite(sqrt(2._dp)*x/omega(z),l)*&\n hermite(sqrt(2._dp)*y/omega(z),m)*exp(-(x*x+y*y)/omega(z)*omega(z))\n \n end function\n\nend module\n", "meta": {"hexsha": "c852130661adaab58518eb18dcfacffe1b34803f", "size": 1344, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "gaussian_fit_fortran/temwave.f95", "max_stars_repo_name": "Havoc3sevens/Gaussian-Fit", "max_stars_repo_head_hexsha": "56d029505106101bed18e9aaf551f084b6486aad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gaussian_fit_fortran/temwave.f95", "max_issues_repo_name": "Havoc3sevens/Gaussian-Fit", "max_issues_repo_head_hexsha": "56d029505106101bed18e9aaf551f084b6486aad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gaussian_fit_fortran/temwave.f95", "max_forks_repo_name": "Havoc3sevens/Gaussian-Fit", "max_forks_repo_head_hexsha": "56d029505106101bed18e9aaf551f084b6486aad", "max_forks_repo_licenses": ["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.7796610169, "max_line_length": 79, "alphanum_fraction": 0.4479166667, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342049451595, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.8012959057306781}} {"text": " REAL FUNCTION ZVAL (X,Y)\n\nC ZVAL is just a simple linear function of x and y so as to\nC generate 3D points on the plane: 3x + 4y - z - 7 = 0, so\nC z = f(x,y) = 3x + 4y - 7\n\n REAL X,Y\n\n ZVAL = 3*X + 4*Y - 7\n\n END\n", "meta": {"hexsha": "716ff68d01601d07100bca30d8742bd908deed46", "size": 239, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/zval.f", "max_stars_repo_name": "n1ckfg/Telidon", "max_stars_repo_head_hexsha": "f4e2c693ec7d67245974b73a602d5d40df6a6d69", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2017-07-08T02:34:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-08T03:42:48.000Z", "max_issues_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/zval.f", "max_issues_repo_name": "n1ckfg/Telidon", "max_issues_repo_head_hexsha": "f4e2c693ec7d67245974b73a602d5d40df6a6d69", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/zval.f", "max_forks_repo_name": "n1ckfg/Telidon", "max_forks_repo_head_hexsha": "f4e2c693ec7d67245974b73a602d5d40df6a6d69", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-02-03T04:44:00.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-05T15:31:18.000Z", "avg_line_length": 19.9166666667, "max_line_length": 60, "alphanum_fraction": 0.5313807531, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452772, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.8007490713626452}} {"text": "! Program to count the sum of digits of a positive integer number\n! Program to count the number of positive numbers in a series of entries\n\nprogram sum_digits\n implicit none\n\n integer :: num, sum1, temp\n integer :: n, count1 = 0,i\n\n print*, \"Enter a positive integer: \"\n read*, num\n\n temp = num\n sum1 = 0\n\n do while (temp /= 0)\n sum1 = sum1 + MOD(temp, 10)\n temp = temp / 10\n !print*, \"Sum is: \", sum1\n !print*, \"Temp is: \", temp\n end do\n\n print*, \"The number is: \", num\n print*, \"And the sum of the digits is: \", sum1\n print*, \"Enter a number from 1 to 10: \"\n read*, n\n print*, \"Enter \", n, \" positive and negative values: \"\n\n do i = 1,n\n print*, \"Enter value \", i, \": \"\n read*, temp\n\n if (temp < 0) then\n CYCLE\n else\n count1 = count1 + 1\n end if\n end do\n\n print*, \"You have entered \", count1, \" positive number(s) out of\" &\n & , n, \" chance(s)\"\nend program sum_digits\n", "meta": {"hexsha": "569e72ffb0214936e499b53cfb2d8bd167df8038", "size": 1013, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran_tut/sum_digits.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": "fortran_tut/sum_digits.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": "fortran_tut/sum_digits.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": 23.5581395349, "max_line_length": 72, "alphanum_fraction": 0.5459032577, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.8007445572229751}} {"text": "module eigenvectors\n !! Module for computing eigenvectors and their associated eigenvalues\n use linear_solvers, only: factor_LU, solve_LU\n implicit none\n\n contains\n subroutine eigen_max(A, v, lambda, maxIter, err_v, v_0)\n !! Given the matrix **A**, computes the eigenvector **v** associated to\n !! the eivenvalue of maximum modulus **lambda** using the power method.\n real, intent(in) :: A(:,:)\n !! Symmetric matrix\n real, intent(out) :: v(size(A,1))\n !! Eigenvector\n real, intent(out) :: lambda\n !! Eigenvalue\n real, intent(in) :: err_v\n !! Precision for the stop criterion\n integer, intent(in) :: maxIter\n !! Maximum number of iterations\n real, intent(in) :: v_0(size(A,1))\n !! Initial vector for the iteration\n\n integer :: i\n real :: u(size(A,1))\n\n u = v_0\n u = u/norm2(u)\n\n do i = 1, maxIter\n v = matmul(A,u)\n lambda = dot_product(u,v)/dot_product(u,u)\n v = v/norm2(v)\n if ( dot_product(u,v)>0)then\n if (norm2(u-v)maxIter ) print*, 'the maximum number of iteration was reached &\n & without obtaining convergence'\n end subroutine\n\n\n\n subroutine eigen_inv(A, v, lambda, p, maxIter, err_v, v_0)\n !! Given the matrix **A**, computes the eigenvector **v** associated to the eivenvalue\n !! **lambda** closer to the value **p** using the inverse power method.\n real, intent(in) :: A(:,:)\n !! Symmetric matrix\n real, intent(out) :: v(size(A,1))\n !! Eigenvector\n real, intent(out) :: lambda\n !! Eigenvalue\n real, intent(in) :: err_v\n !! Precision for the stop criterion\n integer, intent(in) :: maxIter\n !! Maximum number of iterations\n real, intent(in) :: v_0(size(A,1))\n !! Initial vector for the iteration\n real, intent(in) :: p\n !! value close to the eigenvalue wanted\n\n integer :: i\n real :: u(size(A,1)), D(size(A,1),size(A,1))\n real :: Lo(size(A,1),size(A,1)), Up(size(A,1),size(A,1))\n\n u = v_0\n u = u/norm2(u)\n\n D = 0\n do i = 1, size(A,1)\n D(i,i) = p\n end do\n\n\n call factor_LU(A-D,Lo,Up)\n\n do i = 1, maxIter\n v = solve_LU(Lo,Up,u)\n lambda = dot_product(u,v)\n v = v/norm2(v)\n lambda = 1./lambda + p\n if(dot_product(u,v)>0)then\n if(norm2(v-u)maxIter ) print*, 'the maximum number of iteration was reached &\n & without obtaining convergence'\n end subroutine\nend module\n", "meta": {"hexsha": "62ba5cdd80b609b8e164d7c4256a5ae77889fd7a", "size": 3012, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eigen.f90", "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/eigen.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/eigen.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": 31.7052631579, "max_line_length": 92, "alphanum_fraction": 0.5272244356, "num_tokens": 812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8006671796130987}} {"text": "! MIT License\n! Copyright (c) 2019 Sam Miller\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\nmodule math_constants\n !< Summary: Provide global math constants\n !< Author: Sam Miller\n\n use, intrinsic :: iso_fortran_env, only: ik => int32, rk => real64\n\n implicit none\n\n real(rk), parameter :: pi = 4.0_rk * atan(1.0_rk)\n real(rk), parameter :: universal_gas_const = 8.31446261815324_rk\n\ncontains\n real(rk) elemental function rad2deg(rad) result(deg)\n real(rk), intent(in) :: rad\n deg = rad * 180.0_rk / pi\n endfunction\n\n real(rk) elemental function deg2rad(deg) result(rad)\n real(rk), intent(in) :: deg\n rad = deg * pi / 180.0_rk\n endfunction\nendmodule math_constants\n", "meta": {"hexsha": "671861f76875aea2393e57e017c031f4aa667e9f", "size": 1697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/math_constants.f90", "max_stars_repo_name": "smillerc/fvleg_2d", "max_stars_repo_head_hexsha": "b79d59807b8b005a25d7cc25a9fe3d192ecd15a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-03-31T18:33:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T03:23:30.000Z", "max_issues_repo_path": "src/lib/math_constants.f90", "max_issues_repo_name": "smillerc/cato", "max_issues_repo_head_hexsha": "b79d59807b8b005a25d7cc25a9fe3d192ecd15a0", "max_issues_repo_licenses": ["MIT"], "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/math_constants.f90", "max_forks_repo_name": "smillerc/cato", "max_forks_repo_head_hexsha": "b79d59807b8b005a25d7cc25a9fe3d192ecd15a0", "max_forks_repo_licenses": ["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.4651162791, "max_line_length": 80, "alphanum_fraction": 0.747790218, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8824278741843884, "lm_q1q2_score": 0.8006375947167707}} {"text": "MODULE combinatorics\n use num_types\n use rational_mathematics, only: gcd\n implicit none\n private\n public get_permutations, m_partitions_of_n, factorial, nchoosek, k_ary_counter, &\n multinomial, binomial, permutation_parity\n\n type subset_mask\n private\n logical :: init, done\n logical, pointer :: mask(:) => null()\n end type subset_mask\n\n INTERFACE factorial\n MODULE PROCEDURE factorial_int_scalar, factorial_int_rank1, &\n factorial_dp_rank1, factorial_dp_scalar, factorial_long_int\n END INTERFACE factorial\nCONTAINS\n\n !!Binomial coefficient. Computes the number of permutations\n !!of n things, taken k at a time\n !!! This implementation was taken from \"Binomial\n !!Coefficient Computation: Recursion or Iteration?\" by Yannis\n !!Manolopoulos, ACM SIGCSE Bulletin InRoads, Vol.34, No.4, December\n !!2002. http://delab.csd.auth.gr/papers/SBI02m.pdf It is supposed to\n !!be robust against large, intermediate values and to have optimal\n !!complexity. This replaces the original function that was used\n !!until revision 125 GLWH June 2014 \n FUNCTION nchoosek(n,k)\n integer(li) :: nchoosek\n integer, intent(in) :: n,k\n integer(li) :: t ! Variable to accumulate answer in\n integer :: i ! Counter\n if (k < 0 .or. k > n) then\n nchoosek = 0\n return\n end if\n if (k==0 .and. n == 0) then\n nchoosek = 1\n return\n end if\n t = 1\n if (kFinds the binomial coefficient of two different numbers.\n FUNCTION binomial(n,k)\n integer(li) :: binomial\n integer, intent(in) :: n,k\n if (k > n) stop \"Error in arguments to binomial\"\n binomial = nchoosek(n,k)\n\n END FUNCTION binomial\n\n !!Calculates the multinomial for an input list of\n !!numbers.\n !!An array of the exponents of\n !!the term we are taking the multinomial of.\n FUNCTION multinomial(n)\n integer(li) :: multinomial\n integer, intent(in) :: n(:)\n integer(li) :: binomials(size(n,1),2), bins(size(n,1))\n integer :: i\n\n binomials(1,1) = sum(n)\n binomials(1,2) = n(1)\n do i = 2, size(binomials,1)\n binomials(i,1) = binomials(i-1,1) - binomials(i-1,2)\n binomials(i,2) = n(i)\n enddo\n\n do i = 1, size(binomials,1)\n bins(i) = binomial( int(binomials(i,1)) , int(binomials(i,2)) )\n enddo\n\n multinomial = product(bins)\n\n !nt = n; ft = 1\n !ft=factorial(sum(nt))\n !do i = 1, size(n)\n ! if (mod(ft,factorial(nt(i)))/=0) stop \"Bug in multinomial\"\n ! ft = ft/factorial(nt(i))\n !enddo\n !multinomial = ft\n ENDFUNCTION multinomial\n\n !!This subroutine generates all permutations of the\n !! list. Swapping identical items does *not* give another\n !! permutation. List is generated in lexicographical order. Input\n !! list must be in order (or the routine quits with an\n !! error)\n !!The input list for which\n !! permutations are neede.\n !!The output 2d array of possible\n !! permutations.\n SUBROUTINE get_permutations(list,perms)\n integer, intent(in) :: list(:)\n integer, pointer :: perms(:,:)\n\n integer, allocatable:: tempPerms(:,:)\n integer :: Nitems, Np, a(size(list)),i,nuq(size(list))\n integer :: j, l, temp, ip, status\n integer :: ptr ! \"pointer\" to current position in the list of unique items in list\n real(dp) :: tot\n\n Nitems = size(list)\n ! Determine how much temporary storage we will need. Tricky to do this\n ! without overflowing an integer (or even a real)\n call find_unique(list,nuq)\n ! Make a list of terms in the numerator and denominator of the multinomial\n ! and keep a running product\n ptr = 1; tot = 1\n do i = Nitems,1,-1 ! Loop over each term, start at N in the numerator and work down\n if (nuq(ptr)==0) ptr = ptr + 1 ! Keep track of the number in the denominator\n tot = tot*real(i)/nuq(ptr) ! compute multinomial one pair (numer/denom) at a time\n nuq(ptr) = nuq(ptr) - 1\n enddo\n Np = ceiling(tot)\n if (Np < 0) stop \"combinatorics.f90: temporary storage overflow. Cutoffs too big.\"\n\n allocate(tempPerms(Nitems,Np))\n a = list ! Copy of the original input list\n ! Make sure the items are initially ordered\n do i = 1, Nitems-1\n if (a(i+1)Finds the number of unique entries of each type in a\n !!list.\n !!A 1D array of for which the unique\n !!entries are to be found.\n !!A 1D array of the unique elemements of\n !!the input list.\n subroutine find_unique(list,uqlist)\n integer, intent(in) :: list(:)\n integer, intent(out):: uqlist(:)\n integer :: sm\n uqlist = 0\n sm = minval(list) ! smallest value in the list\n do i = 1, size(list) ! loop over the possible number of unique values\n\n uqlist(i) = count(sm==list) ! How many of this size?\n sm = minval(list,mask=(list>sm)) ! Next unique value bigger than the last\n if (count(sm==list)==0) exit ! If there aren't any of this\n ! size then we took the largest already\n enddo\n endsubroutine find_unique\n END SUBROUTINE get_permutations\n\n !!This routine generates a list of all numbers between 0\n !!and n^k-1\n !!Base is the intereger that\n !!will be used as the base of the exponential.\n !!n is an integer that is being\n !!exponentiated.\n !!Resultant 2d list of numbers\n SUBROUTINE k_ary_counter(list,base,n)\n integer, pointer :: list(:,:)\n integer, intent(in) :: base\n integer, intent(in) :: n ! number of digits\n integer :: k, j, il\n integer :: a(n)\n\n k = base; allocate(list(n,k**n))\n il = 1; a = 0\n list(:,il) = a\n do\n j = n ! Number of digits\n do ! Check to see if we need to roll over any digits, start at the right\n if (a(j) /= k - 1) exit\n a(j) = 0 ! Rolling over so set to zero\n j = j - 1; ! Look at the next (going leftways) digit\n if (j < 1) exit ! If we updated the leftmost digit then we're done\n enddo\n if (j < 1) exit ! We're done counting, exit\n a(j) = a(j) + 1 ! Update the next digit\n il = il + 1\n list(:,il) = a\n enddo\n\n ENDSUBROUTINE k_ary_counter\n\n !!This subroutine generates all partions of n into m\n !! blocks. This is needed to generate all possible concentration\n !! vectors for each structures (then within each structure we need\n !! all permutations of atomic configurations...) See page 38 in\n !! Knuth V. 4 Fascicle 3.\n !!Number to be partitioned.\n !!Number of the block.\n !!Resultant array of partition.\n SUBROUTINE m_partitions_of_n(n,m,part)\n integer, intent(in) :: n, m ! number to be partitioned, number of block\n integer, pointer :: part(:,:)\n\n integer :: a(m)\n integer :: ip ! counter for number of partitions\n integer :: x, s ! Temporary variables for swapping/reassigning values\n integer :: j ! index pointer for next position to be incremented\n\n ! First we need to count the number of partitions to know how big\n ! to allocate the \"part\" array (is there a closed form expression\n ! for this? I don't think so but...)\n if (m>n) then; stop \"Bad input for 'm_partitions_of_n' routine\";endif\n if (m<2) then; stop \"Trivial case'm_partitions_of_n' routine\";endif\n ! Initialize the first partition\n a(1) = n - (m-1); a(2:m) = 1\n ip = 0\n do; ip = ip + 1;\n if (a(2) < a(1)-1) then ! \"crumble\" at left if possible\n a(1) = a(1)-1\n a(2) = a(2)+1\n cycle; endif\n if (m==2) exit ! For binary case, we're done here\n ! Find the leftmost position that can be increased\n j = 3 ! This is the leftmost possibility but...\n s = a(1)+a(2)-1\n do while (a(j)>=a(1)-1)\n s = s+a(j)\n j = j+1\n if (j>m) exit\n enddo ! Now s = part(1)+part(2)+...+part(j-1)-1)\n if (j > m) exit ! We're done counting\n x = a(j)+1 ! Store the value of the j-th position incremented by one\n a(j) = x ! Make the j-th position have this value\n j = j-1 ! Now look one to the left\n do while (j>1)\n a(j) = x ! Make this next-left position match the slot that was updated\n s = s - x ! Keep track of how many of the original 'n' are left\n j = j-1 ! Now look to the left again...\n enddo\n a(1) = s ! Now make the leftmost slot take all the leftover...\n enddo\n !if (allocated(part)) deallocate(part)\n allocate(part(ip,m))\n ip = 0; a(1) = n - (m-1); a(2:m) = 1\n do; ip = ip + 1\n ! Visit the partition\n part(ip,:) = a ! store the ip-th partition\n if (a(2) < a(1)-1) then ! \"crumble\" at left if possible\n a(1) = a(1)-1\n a(2) = a(2)+1\n cycle; endif\n if (m==2) exit ! For binary case, we're done here\n ! Find the leftmost position that can be increased\n j = 3 ! This is the leftmost possibility but...\n s = a(1)+a(2)-1\n do while (a(j)>=a(1)-1)\n s = s+a(j)\n j = j+1\n if (j>m) exit\n enddo ! Now s = part(1)+part(2)+...+part(j-1)-1)\n if (j > m) exit ! We're done counting\n x = a(j)+1\n a(j) = x\n j = j-1\n do while (j>1)\n a(j) = x\n s = s - x\n j = j-1\n enddo\n a(1) = s\n enddo\n END SUBROUTINE m_partitions_of_n\n\n !!Factorial of the long int type.\n FUNCTION factorial_long_int(N)\n\n integer(li) :: factorial_long_int, N, i\n factorial_long_int = 1\n do i=2,N;factorial_long_int=factorial_long_int*i;enddo\n END FUNCTION factorial_long_int\n\n !!Factorial of the int type.\n FUNCTION factorial_int_scalar(N)\n integer :: N,i,factorial_int_scalar\n factorial_int_scalar = 1\n do i=2,N; factorial_int_scalar=factorial_int_scalar*i;enddo\n END FUNCTION factorial_int_scalar\n\n !!Factorial of each element of 1D array of type int.\n !!\n FUNCTION factorial_int_rank1(N)\n integer :: N(:),i,factorial_int_rank1(size(N)),j\n factorial_int_rank1 = 1\n do j=1,size(N)\n do i=2,N(j); factorial_int_rank1(j)=factorial_int_rank1(j)*i;enddo;enddo\n END FUNCTION factorial_int_rank1\n\n !!Factorial of each element 1D array of tpye real.\n !!\n FUNCTION factorial_dp_rank1(N)\n real(dp) :: N(:),factorial_dp_rank1(size(N))\n integer :: i,j\n factorial_dp_rank1 = 1._dp\n do j=1,size(N)\n do i=2,nint(N(j)); factorial_dp_rank1(j)=factorial_dp_rank1(j)*i;enddo;enddo\n END FUNCTION factorial_dp_rank1\n\n\n !!Factorial of the tpye real.\n FUNCTION factorial_dp_scalar(N)\n integer :: i\n real(dp):: N,factorial_dp_scalar\n factorial_dp_scalar = 1._dp\n do i=2,nint(N); factorial_dp_scalar=factorial_dp_scalar*i;enddo\n END FUNCTION factorial_dp_scalar\n\n\n !!Finds the parity of a given permuted list aP (must start at 1)\n !! algorithm from: www.cap-lore.com/code/ocaml/parity.html\n !!\n function permutation_parity(aP)\n integer :: permutation_parity\n integer, intent(in) :: aP(:) ! the permuted list\n integer :: v(size(aP)) ! some helper array\n integer :: j,x,p,n\n\n n=size(aP)\n\n ! check if every number i\n do j=1,n\n if (.not. any(aP==j)) stop \"ERROR: invalid list in permuation_parity.\"\n enddo\n\n v = 0\n p = 0\n\n do j=n,1,-1\n if (v(j)>0) then\n p=p+1\n else\n x=j\n do\n x = aP(x)\n v(x) = 1\n if (x==j) exit\n enddo\n endif\n end do\n\n permutation_parity = -(mod(p,2)*2-1)\n end function permutation_parity\nEND MODULE combinatorics\n", "meta": {"hexsha": "90065da15a0892be251b674b6653651b5457f100", "size": 13321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/combinatorics.f90", "max_stars_repo_name": "braydenbekker/symlib", "max_stars_repo_head_hexsha": "5acbf98a437cfca6926f1144a129333bb613771d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2015-07-27T16:12:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T12:24:48.000Z", "max_issues_repo_path": "src/combinatorics.f90", "max_issues_repo_name": "braydenbekker/symlib", "max_issues_repo_head_hexsha": "5acbf98a437cfca6926f1144a129333bb613771d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-05-24T07:51:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-03T18:06:11.000Z", "max_forks_repo_path": "src/combinatorics.f90", "max_forks_repo_name": "braydenbekker/symlib", "max_forks_repo_head_hexsha": "5acbf98a437cfca6926f1144a129333bb613771d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2015-04-02T23:07:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T12:32:20.000Z", "avg_line_length": 35.4281914894, "max_line_length": 106, "alphanum_fraction": 0.6202237069, "num_tokens": 4008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8005173830826512}} {"text": "module linear_transport\n\nimplicit none\n\ncontains\n\n pure real(8) function exact1(x)\n\n real(8), intent(in) :: x\n real(8), parameter :: L = 1.0d0\n real(8), parameter :: gamma = 0.1d0\n real(8), parameter :: U = 1.0d0\n\n exact1 = 1.0d0 - 1.0d0*(exp(x*U/gamma)-1.0d0)/(exp(L*U/gamma)-1.0d0)\n \n end function exact1\n \n ! Model problem to solve\n pure subroutine assemble_system(a, b, npts, V, rhs, sparse)\n\n logical, intent(in) :: sparse \n real(8), intent(in) :: a, b ! bound of domain\n real(8), intent(out) :: V(:,:)\n real(8), intent(out) :: rhs(:)\n integer, intent(in) :: npts ! number of points\n\n ! Local variables\n real(8) :: aa, bb, cc\n real(8) :: h \n integer :: m, n, i, j\n\n real(8), parameter :: L = 1.0d0\n real(8), parameter :: gamma = 0.1d0\n real(8), parameter :: U = 1.0d0\n\n ! Mesh spacing\n h = (b-a)/dble(npts+1)\n\n ! Problem parameters\n aa = -u/(2.0d0*h) - gamma/(h*h)\n bb = 2.0d0*gamma/(h*h)\n cc = u/(2.0d0*h) - gamma/(h*h)\n \n ! Prepare matrix\n V = 0.0d0\n m = npts\n n = npts\n if (sparse .eqv. .true.) then \n\n V(1,:) = [0.0d0, bb, cc]\n do concurrent(i=2:n-1)\n V(i,:) = [aa, bb, cc]\n end do\n V(n,:) = [aa, bb, 0.0d0]\n \n else\n\n do i = 1, m\n do j = 1, n\n if (i .eq. j-1) then\n ! upper diagonal\n V(i,j) = cc\n else if (i .eq. j) then\n ! diagonal\n V(i,i) = bb \n else if (i .eq. j+1) then\n ! lower diagonal\n V(i,j) = aa\n else\n end if\n end do\n end do\n\n end if\n\n ! Assemble the RHS\n rhs = 0.0d0\n rhs(1) = -aa*1.0d0\n rhs(npts) = -cc*0.0d0\n\n end subroutine assemble_system\n\nend module linear_transport\n", "meta": {"hexsha": "0f5a7f42f1884d4981e5bd4736e75aa75b1bce23", "size": 1878, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "physics/steady-transport/linear_transport.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": "physics/steady-transport/linear_transport.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": "physics/steady-transport/linear_transport.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.3571428571, "max_line_length": 72, "alphanum_fraction": 0.470713525, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.800307979235057}} {"text": "! Routine for quadratic approximation\r\n! Igor Lopes, February 2015\r\nSUBROUTINE POLYQUAD(NPOINT,X,F,XMIN,FMIN)\r\n IMPLICIT NONE\r\n REAL(8) R0 /0.0D0/\r\n REAL(8) R2 /2.0D0/\r\n ! Arguments\r\n INTEGER NPOINT\r\n REAL(8) :: XMIN, FMIN\r\n REAL(8),DIMENSION(4) :: X , F\r\n ! Locals\r\n REAL(8) :: A0,A1,A2\r\n ! Begin algorithm\r\n IF(NPOINT.EQ.2)THEN\r\n A2=((F(2)-F(1))/(X(2)-X(1))-F(3))/(X(2)-X(1))\r\n A1=F(3)-R2*A2*X(1)\r\n A0=F(1)-A1*X(1)-A2*X(1)*X(1)\r\n ELSEIF(NPOINT.EQ.3)THEN\r\n A2=((F(3)-F(1))/(X(3)-X(1))-(F(2)-F(1))/(X(2)-X(1)))/(X(3)-X(2))\r\n A1=(F(2)-F(1))/(X(2)-X(1))-A2*(X(1)+X(2))\r\n A0=F(1)-A1*X(1)-A2*X(1)*X(1)\r\n ELSE\r\n WRITE(*,*)'Wrong number of input points in POLYQUAD'\r\n GOTO 99\r\n ENDIF\r\n WRITE(*,*)'Approximation coefficients:'\r\n WRITE(*,*)'a0=',A0\r\n WRITE(*,*)'a1=',A1\r\n WRITE(*,*)'a2=',A2\r\n WRITE(11,*)'Approximation coefficients:'\r\n WRITE(11,*)'a0=',A0\r\n WRITE(11,*)'a1=',A1\r\n WRITE(11,*)'a2=',A2\r\n ! Minimum or Maximum\r\n IF(A2.LT.R0)THEN\r\n WRITE(11,*)'A maximum is found for'\r\n WRITE(*,*)'A maximum is found for'\r\n ELSEIF(A2.GT.R0)THEN\r\n WRITE(11,*)'A minimum is found for'\r\n WRITE(*,*)'A minimum is found for'\r\n ELSE\r\n WRITE(11,*)'Linear function. Neither minimum nor maximum.'\r\n GOTO 99\r\n ENDIF\r\n XMIN=-A1/(R2*A2)\r\n FMIN=A0+A1*XMIN+A2*XMIN*XMIN\r\n WRITE(11,*)'X=',XMIN,'F_approx=',FMIN\r\n WRITE(*,*)'X=',XMIN,'F_approx=',FMIN\r\n99 CONTINUE \r\nEND SUBROUTINE", "meta": {"hexsha": "f9e67b635b2239fc9a247513f88e020c92d1fd16", "size": 1545, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/polynomial_approx/polyquad.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/polynomial_approx/polyquad.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/polynomial_approx/polyquad.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": 30.9, "max_line_length": 73, "alphanum_fraction": 0.5223300971, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.8002962517202095}} {"text": "real*8 function SHPowerLC(c, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power at\n!\tdegree l corresponding to the complex spherical harmonic coefficients c(i, l, m)\n!\n!\tPower(l) = Sum_{m=0}^l | C1lm | **2 + | C2lm | **2 )\n!\n!\tCalling Parameters\n!\t\tc\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\t\n\tcomplex*16, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\n\t\n\tl1 = l+1\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < l1 .or. size(c(1,1,:)) < l1) then\n\t\tprint*, \"SHPowerLC --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHPowerLC = dble(c(1, l1, 1))**2 + aimag(c(1, l1, 1))**2\t! m=0 term\n\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHPowerLC = SHPowerLC + dble(c(i, l1, m1))**2 + aimag(c(i, l1, m1))**2\n\t\tenddo\n\tenddo\n\nend function SHPowerLC\n\n\nreal*8 function SHPowerDensityLC(c, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power per coefficient\n!\t(density) at degree l of the complex spherical harmonic coefficients c(i, l, m)\n!\n!\tPowerSpectralDensity(l) = Sum_{m=0}^l ( | C1lm |**2 + | C2lm |**2 ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tc\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < l1 .or. size(c(1,1,:)) < l1) then\n\t\tprint*, \"SHPowerDensityLC --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHPowerDensityLC = dble(c(1, l1, 1))**2 + aimag(c(1, l1, 1))**2\n\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHPowerDensityLC = SHPowerDensityLC + dble(c(i, l1, m1))**2 + aimag(c(i, l1, m1))**2\n\t\tenddo\n\tenddo\n\t\n\tSHPowerDensityLC = SHPowerDensityLC/dble(2*l+1)\n\nend function SHPowerDensityLC\n\n\ncomplex*16 function SHCrossPowerLC(c1, c2, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power at\n!\tdegree l for the complex spherical harmonic coefficients c1(i, l, m)\n!\tand c2(i,l,m).\n!\n!\tCrossPower = Sum_{m=0}^l ( C11lm*C21lm^* + C12lm*C22lm^* )\n!\n!\tCalling Parameters\n!\t\tc1\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tc2\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < l1 .or. size(c1(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerLC --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < l1 .or. size(c2(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerLC --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHCrossPowerLC = c1(1, l1, 1)*dconjg(c2(1,l1,1))\n\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHCrossPowerLC = SHCrossPowerLC + c1(i, l1, m1)*dconjg(c2(i,l1,m1))\n\t\tenddo\n\tenddo\n\nend function SHCrossPowerLC\n\n\ncomplex*16 function SHCrossPowerDensityLC(c1, c2, l)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power\n!\t(density) at degree l of the complext spherical harmonic coefficients c1(i, l, m)\n!\tand c2(i,l,m).\n!\n!\tCrossPower(l) = Sum_{m=0}^l ( C11lm*C21lm^* + C12lm*C22lm^* ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tc1\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tc2\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t(2, lmax+1, lmax+1).\n!\t\tl\tSpherical harmonic degree to compute power.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: l\n\tinteger i, m, l1, m1\t\n\t\n\tl1 = l+1\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < l1 .or. size(c1(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerDensityLC --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < l1 .or. size(c2(1,1,:)) < l1) then\n\t\tprint*, \"SHCrossPowerDensityLC --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, L+1, L+1) where L is \", l\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\tendif\n\n\tSHCrossPowerDensityLC = c1(1, l1, 1)*dconjg(c2(1,l1,1))\n\t\n\tdo m = 1, l, 1\n\t\tm1 = m+1\n\t\tdo i=1, 2\n\t\t\tSHCrossPowerDensityLC = SHCrossPowerDensityLC + c1(i, l1, m1)*dconjg(c2(i,l1,m1))\n\t\tenddo\n\tenddo\n\t\n\tSHCrossPowerDensityLC = SHCrossPowerDensityLC/dble(2*l+1)\n\nend function SHCrossPowerDensityLC\n\n\nsubroutine SHPowerSpectrumC(c, lmax, spectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power spectrum\n!\tof the complex spherical harmonic coefficients c(i, l, m).\n!\n!\tPower(l) = Sum_{m=0}^l ( | C1lm |**2 + | C2lm |**2 )\n!\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc\tComplex pherical harmonic coefficients, dimensioned as \n!\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tspectra\tArray of length (lmax+1) containing the power\n!\t\t\t\tspectra of c.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < lmax+1 .or. size(c(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumC --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\telseif (size(spectra) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumC --- Error\"\n\t\tprint*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(spectra)\n\t\tstop\n\tendif\n\t\n\tspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tspectra(l1) = dble(c(1, l1, 1))**2 + aimag(c(1, l1, 1))**2\n\t\t\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tspectra(l1) = spectra(l1) + dble(c(i, l1, m1))**2 + aimag(c(i, l1, m1))**2\n\t\t\tenddo\n\t\tenddo\n\tenddo\n\nend subroutine SHPowerSpectrumC\n\n\nsubroutine SHPowerSpectrumDensityC(c, lmax, spectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless power spectrum\n!\tdensity of the complex spherical harmonic coefficients c(i, l, m)\n!\n!\tPowerSpectralDensityC(l) = Sum_{m=0}^l ( C1lm**2 + C2lm**2 ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tspectra\tArray of length (lmax+1) containing the power\n!\t\t\t\tspectra density of c.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c(:,:,:)\n\tinteger, intent(in) :: lmax\n\treal*8, intent(out) ::\tspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c(:,1,1)) < 2 .or. size(c(1,:,1)) < lmax+1 .or. size(c(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumDensityC --- Error\"\n\t\tprint*, \"C must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c(:,1,1)), size(c(1,:,1)), size(c(1,1,:)) \n\t\tstop\n\telseif (size(spectra) < lmax+1) then\n\t\tprint*, \"SHPowerSpectrumDensityC --- Error\"\n\t\tprint*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(spectra)\n\t\tstop\n\tendif\n\n\tspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tspectra(l1) = dble(c(1, l1, 1))**2 + aimag(c(1, l1, 1))**2\n\t\t\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tspectra(l1) = spectra(l1) + dble(c(i, l1, m1))**2 + aimag(c(i, l1, m1))**2\n\t\t\tenddo\n\t\tenddo\n\t\t\n\t\tspectra(l1) = spectra(l1)/dble(2*l+1)\n\tenddo\n\nend subroutine SHPowerSpectrumDensityC\n\n\nsubroutine SHCrossPowerSpectrumC(c1, c2, lmax, cspectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power spectrum\n!\tof the complex spherical harmonic coefficients c1(i, l, m) and c2(1,l,m).\n!\n!\tCrossPower(l) = Sum_{m=0}^l ( C11lm*C21lm^* + C12lm*C22lm^* )\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc1\t\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tc2\t\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\t\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tcspectra\tArray of length (lmax+1) containing the complex cross power\n!\t\t\t\t\tspectra of c.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: lmax\n\tcomplex*16, intent(out) ::\tcspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < lmax+1 .or. size(c1(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumC --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, LMAX+1, LMAX+1) where lmax is\", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < lmax+1 .or. size(c2(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumC --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\telseif (size(cspectra) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumC --- Error\"\n\t\tprint*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(cspectra)\n\t\tstop\n\tendif\n\n\tcspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tcspectra(l1) = c1(1, l1, 1)*dconjg(c2(1, l1, 1))\n\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tcspectra(l1) = cspectra(l1) + c1(i, l1, m1)*dconjg(c2(i, l1, m1))\n\t\t\tenddo\n\t\tenddo\n\tenddo\n\nend subroutine SHCrossPowerSpectrumC\n\n\nsubroutine SHCrossPowerSpectrumDensityC(c1, c2, lmax, cspectra)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the dimensionless cross power spectrum\n!\tdensity of the complex spherical harmonic coefficients c1(i, l, m) and c2(i,l,m).\n!\n!\tCrossPower(l) = Sum_{m=0}^l ( C11lm*C21lm^* + C12lm*C22lm^* ) / (2l+1)\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tc1\t\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tc2\t\tComplex spherical harmonic coefficients, dimensioned as \n!\t\t\t\t\t(2, lmax+1, lmax+1).\n!\t\t\tlmax\t\tSpherical harmonic degree to compute power.\n!\t\tOUT\n!\t\t\tcspectra\tArray of length (lmax+1) containing the complex cross power\n!\t\t\t\t\tspectral density of c.\n!\n!\tWritten by Mark Wieczorek (May 2008).\n!\n!\tCopyright (c) 2008, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\tcomplex*16, intent(in) :: c1(:,:,:), c2(:,:,:)\n\tinteger, intent(in) :: lmax\n\tcomplex*16, intent(out) ::\tcspectra(:)\n\tinteger i, m, l1, m1, l\n\t\n\tif (size(c1(:,1,1)) < 2 .or. size(c1(1,:,1)) < lmax+1 .or. size(c1(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensityC --- Error\"\n\t\tprint*, \"C1 must be dimensioned as (2, LMAX+1, LMAX+1) where lmax is\", lmax\n\t\tprint*, \"Input array is dimensioned \", size(c1(:,1,1)), size(c1(1,:,1)), size(c1(1,1,:)) \n\t\tstop\n\telseif (size(c2(:,1,1)) < 2 .or. size(c2(1,:,1)) < lmax+1 .or. size(c2(1,1,:)) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensityC --- Error\"\n\t\tprint*, \"C2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n\t\tprint*, \"Input array is dimensioned \", size(c2(:,1,1)), size(c2(1,:,1)), size(c2(1,1,:)) \n\t\tstop\n\telseif (size(cspectra) < lmax+1) then\n\t\tprint*, \"SHCrossPowerSpectrumDensityC --- Error\"\n\t\tprint*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n\t\tprint*, \"Input vector has dimension \", size(cspectra)\n\t\tstop\n\tendif\n\n\tcspectra = 0.0d0\n\t\n\tdo l=0, lmax\n\t\tl1 = l+1\n\t\t\n\t\tcspectra(l1) = c1(1, l1, 1)*dconjg(c2(1, l1, 1))\n\n\t\tdo m = 1, l, 1\n\t\t\tm1 = m+1\n\t\t\t\n\t\t\tdo i=1, 2\n\t\t\t\tcspectra(l1) = cspectra(l1) + c1(i, l1, m1)*dconjg(c2(i, l1, m1))\n\t\t\tenddo\n\t\t\t\n\t\tenddo\n\t\t\n\t\tcspectra(l1) = cspectra(l1)/dble(2*l+1)\n\t\t\n\tenddo\n\nend subroutine SHCrossPowerSpectrumDensityC\n\n", "meta": {"hexsha": "37f7715879be9907668596fa2ee439e351b45a02", "size": 14292, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHPowerSpectraC.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/SHPowerSpectraC.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/SHPowerSpectraC.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.9350649351, "max_line_length": 96, "alphanum_fraction": 0.572418136, "num_tokens": 5234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.8002962415119406}} {"text": "program mtx_multi_loop_test\n\n !Undergraduate Student: Arturo Burgos\n !Professor: João Rodrigo Andrade\n !Federal University of Uberlândia - UFU, Fluid Mechanics Laboratory\n !MFLab, Block 5P, Uberlândia, MG, Brazil\n\n\n implicit none !To avoid variable definition problems, checking if they are correctly defined\n integer :: i, j, k\n real :: soma\n real, DIMENSION(3,3) :: mtx1, mtx2, mtx3, mtx4, mtx5\n DOUBLE PRECISION :: start, finish\n \n call random_number(mtx1)\n call random_number(mtx2)\n \n\n !Here I initialize the first matrix\n print *, 'The random mtx1 matrix is : '\n\n write (*,1) '---------------- New Slice ------------------'\n 1 format(a47)\n\n do i = 1,3\n \n print*, mtx1(i,:) \n \n end do\n\n write (*,2) '---------------- New Slice ------------------'\n 2 format(a47)\n \n write(*,'(//A//)')\n\n !Here I initialize the second matrix\n print *, 'The random mtx2 matrix is : '\n\n write (*,3) '---------------- New Slice ------------------'\n 3 format(a47)\n\n do i = 1,3\n \n print*, mtx2(i,:) \n \n end do\n\n write (*,4) '---------------- New Slice ------------------'\n 4 format(a47)\n\n\n write(*,'(////A///)')\n\n\n !Here I print the multiplication matrix result point by point \n !(the same as mtx1.*mtx2 in Julia or MATLAB)\n mtx3 = mtx1*mtx2\n \n print *, 'The point by point multiplication matrix result mtx3 is : '\n\n write (*,5) '---------------- New Slice ------------------'\n 5 format(a47)\n\n do i = 1,3\n \n print*, mtx3(i,:) \n \n end do\n\n write (*,6) '---------------- New Slice ------------------'\n 6 format(a47)\n\n write(*,'(////A///)')\n\n !Here I print the multiplication matrix result using matmul \n !(the same as mtx1.mtx2 in Julia or MATLAB)\n mtx5 = matmul(mtx1,mtx2)\n\n print *, 'The point by point multiplication matrix result mtx5 is : '\n\n write (*,9) '---------------- New Slice ------------------'\n 9 format(a47)\n\n do i = 1,3\n \n print*, mtx5(i,:) \n \n end do\n\n write (*,10) '---------------- New Slice ------------------'\n 10 format(a47)\n\n call cpu_time(start)\n\n do i = 1,3\n\n do j = 1,3\n soma = 0\n do k = 1,3\n \n soma = soma + mtx1(i,k)*mtx2(k,j)\n mtx4(i,j) = soma\n\n end do\n\n end do\n\n end do\n\n call cpu_time(finish)\n\n write(*,'(////A///)')\n\n print *, 'The multiplication matrix result mtx4 is : '\n\n write (*,7) '---------------- New Slice ------------------'\n 7 format(a47)\n\n do i = 1,3\n \n print*, mtx4(i,:) \n \n end do\n\n write (*,8) '---------------- New Slice ------------------'\n 8 format(a47)\n\n write(*,'(A/)') \n print '(\"Elapsed time is: \",f6.5,\" seconds\")', finish - start\n\nend program mtx_multi_loop_test", "meta": {"hexsha": "c476676172dc63b99e9de126a401e73f598e0755", "size": 2958, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/2_ex/mtx_multi_loop_test.f90", "max_stars_repo_name": "bangyen/Comparing-Languages", "max_stars_repo_head_hexsha": "07fd760501f03482229831652663a5919987c30c", "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": "Fortran/2_ex/mtx_multi_loop_test.f90", "max_issues_repo_name": "bangyen/Comparing-Languages", "max_issues_repo_head_hexsha": "07fd760501f03482229831652663a5919987c30c", "max_issues_repo_licenses": ["MIT"], "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/2_ex/mtx_multi_loop_test.f90", "max_forks_repo_name": "bangyen/Comparing-Languages", "max_forks_repo_head_hexsha": "07fd760501f03482229831652663a5919987c30c", "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": 22.5801526718, "max_line_length": 96, "alphanum_fraction": 0.4597701149, "num_tokens": 782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.9173026646724284, "lm_q1q2_score": 0.8002065774008418}} {"text": "!\tNormal weights for even spacing with centering at 0.\r\n!\tpspread is specified as the range of the quadrature points.\r\n!\t\tIt is computed automatically if the input is not positive.\r\n!\tQuadrature points are returned in points.\r\n!\tQuadrature weights are returned in weights.\r\nsubroutine normalweight(pspread,points,weights)\r\nimplicit none\r\n\r\nreal(kind=8),intent(in)::pspread\r\nreal(kind=8),intent(out)::points(:),weights(:)\r\n\r\n!\ti counts points.\r\n\r\ninteger::i\r\n!\tave is the average of the integers 1 to size(points)\r\n!\tb is the multiplier.\r\n!\tbase is the raw grid.\r\n\r\n\r\n\r\n\r\nreal(kind=8)::ave,b,base(size(points)),div\r\n\r\nave=(1.0_8+size(points))/2.0_8\r\nb=0.0_8\r\ndo i=1,size(points)\r\n\tbase(i)=i-ave\r\nend do\r\n!\tIf pspread is positive, then points are determined from spread.\r\nif(pspread>0.0_8) then\r\n\tb=pspread/(size(points)-1)\r\n\t\r\nelse\r\n if(size(points)>0) b=2.0_8/(size(points)-1.0_8)**0.333333333333333_8\r\nend if\r\npoints=b*base\r\nweights=exp(-points*points/2.0_8)\r\ndiv=sum(weights)\r\nweights=weights/div\r\nreturn\r\nend subroutine normalweight\r\n\r\n\r\n", "meta": {"hexsha": "67b4de83407552471c2b856e5b22dc9c94820825", "size": 1045, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/normalweight.f95", "max_stars_repo_name": "EducationalTestingService/MIRT", "max_stars_repo_head_hexsha": "158b1dee593988cc31b75886a94b212b4bd9d2e4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-09-24T14:31:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-22T00:13:42.000Z", "max_issues_repo_path": "Source/normalweight.f95", "max_issues_repo_name": "EducationalTestingService/MIRT", "max_issues_repo_head_hexsha": "158b1dee593988cc31b75886a94b212b4bd9d2e4", "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": "Source/normalweight.f95", "max_forks_repo_name": "EducationalTestingService/MIRT", "max_forks_repo_head_hexsha": "158b1dee593988cc31b75886a94b212b4bd9d2e4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-09T09:31:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-09T09:31:16.000Z", "avg_line_length": 23.75, "max_line_length": 73, "alphanum_fraction": 0.7119617225, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.80019437654488}} {"text": " program simulate\n implicit none\n double precision I, beta, gamma, iota, N, delta_t\n double precision L, val1, ifrac\n\n I = 1.0\n beta = 0.1\n gamma = 0.05\n iota = 0.01\n N = 1000.0\n delta_t = 0.1\n\n L = beta * (I + iota) / N\n val1 = -L * delta_t\n ifrac = 1.0 - exp(val1)\n\n write (*,*) beta, gamma, iota, N, delta_t\n write (*,*) L, val1, ifrac\n\n stop\n end program simulate\n\n", "meta": {"hexsha": "6b52068c11ba61e506a058f8de7e7de3277b2f92", "size": 454, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scripts/program_analysis/for_py_output_diff/tmp1.f", "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": "scripts/program_analysis/for_py_output_diff/tmp1.f", "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": "scripts/program_analysis/for_py_output_diff/tmp1.f", "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": 19.7391304348, "max_line_length": 55, "alphanum_fraction": 0.5022026432, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.8000934351727099}} {"text": "module timeutils\nuse phys_consts, only: wp\nuse, intrinsic :: iso_fortran_env, only: sp=>real32, dp=>real64, int32, int64\n\nimplicit none (type, external)\nprivate\npublic :: ymd2doy, sza, dateinc, utsec2filestem, date_filename, day_wrap, find_lastdate, find_time_elapsed\n\nreal(wp), parameter :: pi = 4._wp*atan(1._wp)\n\ncontains\n\nelemental integer function daysmonth(year, month) result(days)\n\ninteger, intent(in) :: year, month\ninteger :: monthdays(12)\n\nif ((year < 1600) .or. (year > 2500)) error stop 'is year specified correctly?'\nif ((month < 1) .or. (month > 12)) error stop 'impossible month'\n\nmonthdays = [31,28,31,30,31,30,31,31,30,31,30,31]\n\nif (mod(year, 4)==0 .and. mod(year, 100)/=0 .or. mod(year, 400) == 0) monthdays(2)=29\n\ndays = monthdays(month)\n\nend function daysmonth\n\n\nelemental integer function ymd2doy(year, month, day) result(doy)\n\ninteger, intent(in) :: year, month, day\ninteger :: i\n\nif ((day < 1) .or. (day > daysmonth(year, month))) error stop 'impossible day'\n\ndoy = 0\ndo i = 1, month-1\n doy = doy + daysmonth(year, i)\nenddo\n\ndoy = doy + day\n\nend function ymd2doy\n\n\nelemental function sza(year, month, day, UTsec,glat,glon)\n!! computes sza in radians\n!! CALCULATE SOLAR ZENITH ANGLE OVER A GIVEN GET OF LAT/LON\n\ninteger, intent(in) :: year, month, day\nreal(wp), intent(in) :: UTsec\nreal(wp), intent(in) :: glat,glon\nreal(wp) :: sza\n\nreal(wp), parameter :: tau = 2._wp*pi\n\nreal(wp) :: doy,soldecrad\nreal(wp) :: lonrad,LThrs,latrad,hrang\n\n!> SOLAR DECLINATION ANGLE\ndoy = ymd2doy(year, month, day)\nsoldecrad = -23.44_wp*cos(tau/365._wp*(doy+10)) * pi/180\n\n!> HOUR ANGLE\nlonrad=glon*pi/180\nlonrad = modulo(lonrad, 2*pi)\n\nLThrs=UTsec/3600._wp+lonrad/(pi/12._wp)\nhrang=(12-LThrs)*(pi/12._wp)\n\n!> SOLAR ZENITH ANGLE\nlatrad=glat*pi/180._wp\nsza=acos(sin(soldecrad)*sin(latrad)+cos(soldecrad)*cos(latrad)*cos(hrang))\n\nend function sza\n\n\npure subroutine dateinc(dtsec, ymd, UTsec)\n!! increment datetime by dtsec\n\nreal(wp), intent(in) :: dtsec\n!! seconds to increment\ninteger, intent(inout) :: ymd(3)\n!! year, month, day of month\nreal(wp), intent(inout) :: UTsec\n!! seconds since midnight UTC\n\ninteger :: year,month,day\ninteger :: monthinc !< we incremented the month\n\nyear=ymd(1); month=ymd(2); day=ymd(3);\n\nif (day < 1) error stop 'temporal:timeutils:dateinc(): days are positive integers'\nif (utsec < 0) error stop 'negative UTsec, simulation should go forward in time only!'\nif (dtsec < 0) error stop 'negative dtsec, simulation should go forward in time only!'\nif (dtsec > 86400) error stop 'excessively large dtsec > 86400, simulation step should be small enough!'\n\nUTsec = UTsec + dtsec\ndo while (UTsec >= 86400)\n UTsec = UTsec - 86400._wp\n day = day+1\n call day_wrap(year, month, day)\nend do\n\nymd(1)=year; ymd(2)=month; ymd(3)=day; !replace input array with new date\n\nend subroutine dateinc\n\n\nrecursive pure subroutine day_wrap(year, month, day)\n!! increment date if needed, according to day\n!! that is, if day is beyond month, increment month and year if needed\ninteger, intent(inout) :: year, month, day\n\nif (month < 1 .or. day < 1) error stop 'day_wrap: months and days must be positive'\n\n!> wrap months\ndo while (month > 12)\n month = month - 12\n year = year + 1\nend do\n\n!> wrap days\ndo while (day > daysmonth(year, month))\n day = day - daysmonth(year, month)\n month = month + 1\n call day_wrap(year, month, day)\nend do\n\nend subroutine day_wrap\n\n\npure function date_filename(outdir, ymd, UTsec)\n!! GENERATE A FILENAME stem OUT OF A GIVEN DATE/TIME\n!! (does not include suffix like .h5)\n\ncharacter(*), intent(in) :: outdir\ninteger, intent(in) :: ymd(3)\nclass(*), intent(in) :: UTsec\ncharacter(:), allocatable :: date_filename\n\ncharacter(len=21) :: stem\n\nstem = utsec2filestem(ymd, UTsec)\n\ndate_filename = outdir // '/' // stem\n\nend function date_filename\n\n\npure character(21) function utsec2filestem(ymd, UTsec)\n!! file stem is exactly 21 characters long, per Matt Z's de facto spec.\n!! we keep microsecond dummy precision filenames to be legacy compatible\n!! true filename resolution is 10 milliseconds due to real32 7 digits of precision vis 86400 second day.\ninteger, intent(in) :: ymd(3)\nclass(*), intent(in) :: UTsec\n!! UTC second: real [0.0 .. 86400.0)\n\ncharacter(12) :: sec_str\ninteger :: year, month, day, seconds, millisec, frac\n\nyear = ymd(1)\nmonth = ymd(2)\nday = ymd(3)\n\nselect type(UTsec)\n type is (real(sp))\n !! round to nearest ten milliseconds\n millisec = nint(UTsec * 100) * 10\n type is (real(dp))\n !! round to nearest ten milliseconds\n millisec = nint(UTsec * 100) * 10\n type is (integer(int32))\n millisec = UTsec * 1000\n type is (integer(int64))\n millisec = int(UTsec) * 1000\n class default\n error stop \"timeutils.f90:utsec2filestem unknown UTsec type\"\nend select\n\nseconds = millisec / 1000 !< truncate fractional second\nif (seconds < 0 .or. seconds > 86400) error stop 'timeutils.f90::utsec2filestem did NOT satisfy 0 <= seconds < 86400'\nif (seconds == 86400) then\n !> FIXME: This corner case is from not using integers for microseconds\n ! write(stderr,*) 'utsec2filestem: FIXME: patching UTsec=86400 to next day midnight'\n day = day+1\n seconds = 0\n millisec = 0\n call day_wrap(year, month, day)\nendif\n\nfrac = millisec*1000 - seconds * 1000000 !< microseconds\n\nwrite(sec_str, '(I5.5, A1, I6.6)') seconds, '.', frac\n\nwrite(utsec2filestem, '(i4,I2.2,I2.2,a13)') year, month, day, '_' // sec_str\n\nend function utsec2filestem\n\n\npure subroutine find_lastdate(ymd0,UTsec0,ymdtarget,UTsectarget,cadence,ymd,UTsec)\n\n!> Compute the last date before the target date based on a start date and date cadence. The\n! file is assumed to exist and programmer needs to check for existence outside this\n! procedure.\n! FIXME: this will occasionally hang and may need to be re-examined at some point...\n\ninteger, dimension(3), intent(in) :: ymd0\nreal(wp), intent(in) :: UTsec0\ninteger, dimension(3), intent(in) :: ymdtarget\nreal(wp), intent(in) :: UTsectarget\nreal(wp), intent(in) :: cadence\ninteger, dimension(3), intent(out) :: ymd\nreal(wp), intent(out) :: UTsec\n\ninteger, dimension(3) :: ymdnext\nreal(wp) :: UTsecnext\nlogical :: flagend\n\n\nymd=ymd0\nUTsec=UTsec0\nymdnext=ymd0\nUTsecnext=UTsec0\nflagend=ymdnext(1)>=ymdtarget(1) .and. ymdnext(2)>=ymdtarget(2) .and. ymdnext(3)>=ymdtarget(3) .and. UTsecnext>UTsectarget &\n .or. ymdnext(1)>ymdtarget(1) .or. ymdnext(2)>ymdtarget(2) .or. ymdnext(3)>ymdtarget(3) ! in case the first time step is the last before target\ndo while ( .not.(flagend) )\n ymd=ymdnext\n UTsec=UTsecnext\n call dateinc(cadence,ymdnext,UTsecnext)\n flagend=ymdnext(1)>=ymdtarget(1) .and. ymdnext(2)>=ymdtarget(2) .and. ymdnext(3)>=ymdtarget(3) .and. UTsecnext>UTsectarget &\n .or. ymdnext(1)>ymdtarget(1) .or. ymdnext(2)>ymdtarget(2) .or. ymdnext(3)>ymdtarget(3)\nend do\n! When the loops exits ymd,UTsec have the date of the last output file before the given target time OR the first output file in the case that the target date is before the begin date...\n\nend subroutine find_lastdate\n\n\npure function find_time_elapsed(ymdstart,UTsecstart,ymdend,UTsecend,dt) result(telapsed)\n\n! finds the amount of time that has elapsed between a given start and end date, using a given dt increment\n! the resulting elapsed time will be the smallest multiple of dt that is >= true elapsed time\n\n!! inputs\ninteger, dimension(3), intent(in) :: ymdstart,ymdend\nreal(wp), intent(in) :: UTsecstart,UTsecend\nreaL(wp), intent(in) :: dt\n\ninteger, dimension(3) :: ymdnow\nreal(wp) :: UTsecnow\n\nreal(wp) :: telapsed !! output\n\ntelapsed=0._wp; ymdnow=ymdstart; UTsecnow=UTsecstart;\ndo while (.not. (all(ymdend==ymdnow) .and. UTsecnow>UTsecend) )\n call dateinc(dt,ymdnow,UTsecnow)\n telapsed=telapsed+dt\nend do\ntelapsed=telapsed-dt\n\nend function find_time_elapsed\n\n\nend module timeutils\n", "meta": {"hexsha": "565ee8b4e28e3629a261da2e3ae1f1073558fa40", "size": 7776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/temporal/timeutils.f90", "max_stars_repo_name": "gemini3d/GEMINI", "max_stars_repo_head_hexsha": "4655db755101a127bf1bfeddefd6c021f39b1bdb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-06-17T20:51:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-12T17:46:00.000Z", "max_issues_repo_path": "src/temporal/timeutils.f90", "max_issues_repo_name": "gemini3d/gemini", "max_issues_repo_head_hexsha": "4655db755101a127bf1bfeddefd6c021f39b1bdb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-04-08T22:24:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-15T14:06:41.000Z", "max_forks_repo_path": "src/temporal/timeutils.f90", "max_forks_repo_name": "mattzett/GEMINI", "max_forks_repo_head_hexsha": "4655db755101a127bf1bfeddefd6c021f39b1bdb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-10T16:01:08.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-17T16:08:50.000Z", "avg_line_length": 29.2330827068, "max_line_length": 185, "alphanum_fraction": 0.7125771605, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659995, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.8000934228600182}} {"text": "subroutine sobel(n, m, im, imx, imy, imxy)\n implicit none\n integer, intent(in) :: n,m\n integer(kind=4), dimension(:,:), intent(in) :: im \n integer(kind=4), dimension(:,:), intent(inout) :: imx, imy, imxy\n\n integer :: i,j\n integer(kind=4) :: valuex, valuey\n\n do i=2,n-1\n do j=2,m-1\n\n valuex = 2*im(i,j-1) + im(i-1,j-1) + im(i+1,j-1) \n valuex = valuex -2*im(i,j+1) - im(i-1,j+1) -im(i+1,j+1)\n imx(i,j) = abs(valuex)\n\n valuey = 2*im(i-1,j) + im(i-1,j+1) + im(i-1,j-1)\n valuey = valuey - 2*im(i+1,j) - im(i+1,j+1) - im(i+1,j-1)\n imy(i,j) = abs(valuey)\n\n imxy(i,j) = sqrt(1.*valuex**2+1.*valuey**2)/sqrt(2.)\n end do\n end do\nend subroutine sobel\n", "meta": {"hexsha": "d52f19a06b311824950381298dfce5e4c9e2261f", "size": 690, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sobel_module.f90", "max_stars_repo_name": "vdelmas/sobel", "max_stars_repo_head_hexsha": "b40b36ab36761fd66182c6fde6c2d02dcaa6556a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sobel_module.f90", "max_issues_repo_name": "vdelmas/sobel", "max_issues_repo_head_hexsha": "b40b36ab36761fd66182c6fde6c2d02dcaa6556a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-08-17T21:34:51.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-17T21:43:14.000Z", "max_forks_repo_path": "sobel_module.f90", "max_forks_repo_name": "vdelmas/sobel", "max_forks_repo_head_hexsha": "b40b36ab36761fd66182c6fde6c2d02dcaa6556a", "max_forks_repo_licenses": ["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.6, "max_line_length": 66, "alphanum_fraction": 0.5376811594, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.8000803335166364}} {"text": "module gcd_module\n implicit none\n\n contains\n integer function gcd(a, b)\n implicit none\n\n integer, intent(inout) :: a, b\n integer :: temp\n\n do while (b/=0)\n temp = mod(a,b)\n a = b\n b = temp\n end do\n gcd = a\n end function\nend module\n\nprogram ch1210\n ! gcd After Removing Recursion\n use gcd_module\n implicit none\n\n integer :: i, j, result\n\n print *, 'type in two integers'\n read *, i, j\n result = gcd(i,j)\n print *, 'gcd is ', result\nend program\n", "meta": {"hexsha": "2fab3ad2f3e638df4feb4dfce4bf13dd50a6a22e", "size": 554, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch12/ch1210.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/ch1210.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/ch1210.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": 17.3125, "max_line_length": 38, "alphanum_fraction": 0.5342960289, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.8000067350800777}} {"text": "!@brief generate random unit vector\n!! Use following formula for XY plane\n!! $$ e_x = r \\cdot cos(\\phi) $$\n!! $$ e_y = r \\cdot sin(\\phi) $$\n!! For case in 3D space we change $r$ to $sin$ and $cos$\n!! $$ e_x = sin(\\theta) \\cdot cos(\\phi) $$\n!! $$ e_y = sin(\\theta) \\cdot sin(\\phi) $$\n!! $$ e_y = cos(\\theta) $$\n!! We have to define $r$ non-negative, therefore define \n!! $$ \\theta = arccos(\\tau) $$ \n!! $$ \\tau = \\textit{N}(-1,1) $$ \n!! The angle $\\phi \\in \\textit{N}(-2\\pi;2\\pi) $, where \n!! $\\textit{N}(a,b)$ is uniform distribution in range $[a,b)$ \n!------------------------------------------------------------------\npure subroutine set_unit_vector_sub(dk,dv) \n USE prec_mod\n USE constants, ONLY: f_zero, f_pi\n implicit none\n real(prec), dimension(*), intent(IN) :: dk !< initial angles in polar system of coordinatesgeneration of random numbers in [0,1)\n real(prec), dimension(1:3),intent(OUT) :: dv !< Return vector \n real(prec) :: dtheta !< angle [0,Pi]\n real(prec) :: dtau !< temporal number [-1, 1)\n real(prec) :: dphi !< angle [-Pi,Pi)\n \n ! CALL RANDOM_NUMBER(dk)\n\n dphi = dk(1) * 2.0d0 * f_pi\n dtau = dk(2) * 2.0d0 - 1.0d0\n dtheta = ACOS(dtau)\n dv(1) = SIN(dtheta) * COS(dphi)\n dv(2) = SIN(dtheta) * SIN(dphi)\n dv(3) = COS(dtheta)\n RETURN\nend subroutine set_unit_vector_sub\n\n\n!----------------------------------------------------------------------\n!@brief Calculate normalized cross product\n!!\npure subroutine cross_product_sub(a, b, cr_p) !result(r)\n USE prec_mod\n implicit none\n real(prec), parameter :: small = 1.0d-30 !< Small value\n real(prec), dimension(3) , intent(IN) :: a !< first vector\n real(prec), dimension(3) , intent(IN) :: b !< second vector\n real(prec), dimension(3) , intent(OUT) :: cr_p !< result vector\n real(prec), dimension(3) :: r !< temporary vector\n real(prec) :: d !< asb of result vector\n\n r(1) = a(2) * b(3) - a(3) * b(2)\n r(2) = a(3) * b(1) - a(1) * b(3)\n r(3) = a(1) * b(2) - a(2) * b(1)\n\n d = SQRT(SUM(r(1:3)**2))\n\n cr_p(1:3) = r(1:3) / (d + small)\n\n RETURN \nend subroutine cross_product_sub\n\n\n!@brief Check subroutine cross pruduct \nsubroutine check_cross()\n USE prec_mod\n implicit none\n real(prec),dimension(3) :: i,j,k\n real(prec),dimension(3) :: res\n ! real*8 :: cross_product\n integer :: m\n\n i(1:3) = (/ 1.d0 , 0.d0 , 0.d0 /)\n j(1:3) = (/ 0.d0 , 1.d0 , 0.d0 /)\n k(1:3) = (/ 0.d0 , 0.d0 , 1.d0 /)\n do m=1, 3\n write(*,'(i10,3es10.2)') m, i(m),j(m),k(m)\n enddo\n\n write(*,*) \"Call cross_product\"\n ! res = cross_product(i(1:3),j(1:3))\n CALL cross_product_sub(i,j,res)\n write(*,'(3es10.2)') res\n CALL cross_product_sub(j,k,res)\n write(*,'(3es10.2)') res\n CALL cross_product_sub(k,i,res)\n write(*,'(3es10.2)') res\n\n return\nend subroutine check_cross", "meta": {"hexsha": "8274015f7eade81f49471f8261e45512c0ac8344", "size": 2810, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/set_unit_vector.f90", "max_stars_repo_name": "folk85/gen_turb", "max_stars_repo_head_hexsha": "4390938c4cefae334e95414f83b9c484991bff67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-10T07:42:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-10T07:42:29.000Z", "max_issues_repo_path": "src/set_unit_vector.f90", "max_issues_repo_name": "folk85/gen_turb", "max_issues_repo_head_hexsha": "4390938c4cefae334e95414f83b9c484991bff67", "max_issues_repo_licenses": ["MIT"], "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/set_unit_vector.f90", "max_forks_repo_name": "folk85/gen_turb", "max_forks_repo_head_hexsha": "4390938c4cefae334e95414f83b9c484991bff67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-08T20:08:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-08T20:08:49.000Z", "avg_line_length": 31.9318181818, "max_line_length": 131, "alphanum_fraction": 0.5604982206, "num_tokens": 1016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286373, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.800004822561238}}